我正在尝试运行一个简单的 hello world 示例,并且已经需要一些时间来弄清楚要使用的包含现在我验证了包含路径,QApplication 实际上应该在那里,但它会引发上述错误。为清楚起见,我的代码:
#include <QtWidgets/QApplication>
#include <QtWidgets/QPushButton>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QPushButton *button = new QPushButton("Hello world!");
button->show();
return app.exec();
}
我尝试使用第一个qmake -project进行编译,然后是qmake,最后是 make,然后出现以下错误:
qt_hello_world.o: In function 'main':
undefined reference to QApplication::QApplication(int&, char**, int)
qt_hello_world.cpp: undefined reference to QPushButton::QPushButton(QString const&, QWidget*)
qt_hello_world.cpp: undefined reference to QWidget::show()
qt_hello_world.cpp: undefined reference to QApplication::exec()
qt_hello_world.cpp: undefined reference to QApplication::~QApplication()
qt_hello_world.cpp: undefined reference to QApplication::~QApplication()
由 qmake 创建的 Makefile 包含到包含 QtWidgets/QApplication 的 qt5 目录的正确包含路径,QApplication 文件仅包含包含实际类 QApplication 的 qapplication.h 头文件。