CMake链接问题:未定义对Button :: mousePressEvent(QGraphicsSceneMouseEvent *)的引用

时间:2018-10-25 17:49:31

标签: c++ qt cmake

我正在尝试使用cmake编译Qt组项目。它一直有效,直到我添加了GUI部分。 main.cpp:

0

cmake:

#include <QtWidgets> 

int start_GUI(int argc, char *argv[]){
    QApplication a(argc, argv); 
    Window * window = new Window();
    SSConnection *ssc = new SSConnection();
    Window window;
    return a;
}

输出:

cmake_minimum_required(VERSION 3.6)   
project(client)              
set(CMAKE_CXX_STANDARD 11)          
set(SOURCE_FILES  main.cpp)

find_package(Qt5Widgets REQUIRED)
find_package(Qt5WebSockets REQUIRED)
find_package(Qt5Gui REQUIRED)

set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_INCLUDE_CURRENT_DIR ON)

add_executable(client_main ${SOURCE_FILES}) 

qt5_use_modules(client_main Widgets Gui WebSockets)

Button类只是一个QObject,用于向屏幕添加按钮 按钮:

undefined reference to `Button::mousePressEvent(QGraphicsSceneMouseEvent*)'
undefined reference to `non-virtual thunk to Button::mousePressEvent(QGraphicsSceneMouseEvent*)'

有关如何解决链接错误的任何建议

1 个答案:

答案 0 :(得分:0)

要解决链接器错误,请实施此方法或将其删除。

void mousePressEvent(QGraphicsSceneMouseEvent * event);