error: undefined reference to 'QApplication::QApplication(int&, char**, int)'
源码:
#include <QtWidgets/QApplication>
#include <QtWidgets/QMessageBox>
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QMessageBox::information(0, "ok", "ok");
return app.exec();
}
出错信息:
../nhfjyx/main.cpp:7: error: undefined reference to 'QApplication::QApplication(int&, char**, int)'
../nhfjyx/main.cpp:9: error: undefined reference to 'QMessageBox::information(QWidget*, QString const&, QString const&, QFlags<QMessageBox::StandardButton>, QMessageBox::StandardButton)'
../nhfjyx/main.cpp:11: error: undefined reference to 'QApplication::exec()'
../nhfjyx/main.cpp:11: error: undefined reference to 'QApplication::~QApplication()'
../nhfjyx/main.cpp:11: error: undefined reference to 'QApplication::~QApplication()'
collect2: error: ld returned 1 exit status
make: *** [libnhfjyx.so] Error 1
问题:我在windows和mac上边都遇到了同样的问题,应该是什么库没有导进来,但是具体的我就不知道了,请大家帮我看看,我用的是Qt5.2测试版的,类似Qt5.1,下边这三行代码是报错的
QApplication app(argc, argv);
QMessageBox::information(0, "ok", "ok");
return app.exec(); Qt5.2 Qt?android?IOS
[解决办法]
#include <qmessagebox.h>
#include <qapplication.h>
[解决办法]
估计你的.pro文件没有加控件组件。
CONFIG += widgets还是 QT += gui 有点忘记了。你看看呢
[解决办法]
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
[解决办法]
greaterThan(QT_MAJOR_VERSION, 5): QT += widgets
else QT += gui
[解决办法]
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets