【发布时间】:2018-10-25 17:49:31
【问题描述】:
我正在尝试使用 cmake 编译一组 Qt 项目。它一直有效,直到我添加了 GUI 部分。 main.cpp:
#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:
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)
输出:
undefined reference to `Button::mousePressEvent(QGraphicsSceneMouseEvent*)'
undefined reference to `non-virtual thunk to Button::mousePressEvent(QGraphicsSceneMouseEvent*)'
Button 类只是一个 QObject,用于在屏幕上添加一个按钮 按钮:
class Button : public QObject , public QGraphicsRectItem
{
Q_OBJECT
public:
Button(QString name, QGraphicsItem * parent = NULL);
void mousePressEvent(QGraphicsSceneMouseEvent * event);
signals:
void clicked();
private:
QGraphicsTextItem * text;
QPushButton * button;
QGraphicsRectItem * rect;
};
关于如何修复链接错误的任何建议
【问题讨论】:
-
什么是
Button?,请提供minimal reproducible example -
你试过用 qmake 运行它吗?你有没有清理过它并重建?
-
这是一个在 QtCreator 中创建的项目,因此可以使用 qmake 运行。