简体   繁体   English

qt5 对“QApplication::QApplication(int&, char**, int)”的未定义引用

[英]qt5 undefined reference to 'QApplication::QApplication(int&, char**, int)'

I'm trying to get a simple hello world example running, and already needed some time to figure out what includes to use Now I verified the include paths, the QApplication should actually be there, but it throws the above error.我正在尝试运行一个简单的 hello world 示例,并且已经需要一些时间来确定要使用的包含内容 现在我验证了包含路径,QApplication 实际上应该在那里,但它抛出了上述错误。 For clarity my code:为了清楚起见,我的代码:

#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();
}

I tried compiling using first qmake -project , then qmake and finally make and then got the following errors:我试图用第一QMAKE -project编译,然后QMAKE最终使然后得到了以下错误:

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()

The Makefile created by qmake contains the correct include path to the qt5 directory which contains the QtWidgets/QApplication, the QApplication file just includes the qapplication.h header that contains the actual class QApplication. qmake 创建的 Makefile 包含正确的包含路径到包含 QtWidgets/QApplication 的 qt5 目录,QApplication 文件只包含包含实际类 QApplication 的 qapplication.h 头文件。

The tutorial https://wiki.qt.io/Qt_for_Beginners is fully updated so you must modify it.教程https://wiki.qt.io/Qt_for_Beginners已完全更新,因此您必须对其进行修改。 Change to:更改为:

TEMPLATE = app
TARGET = callboot-ui.exe
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
HEADERS +=
SOURCES += main.cpp

TL; TL; DR;博士;

In the case of @jww it has an error in the following line of the .pro:@jww的情况下,它在 .pro 的以下行中出现错误:

greaterThan(QT_MAJOR_VERSION, 5): QT += core gui widgets

The error is caused because greaterThan(QT_MAJOR_VERSION, 5) verifies that the major version of Qt is greater than 5 to add sub-modules, but the latest version of Qt is 5 .13.2 is not greater than 5, so it is not linked the modules causing the error shown.报错是因为greaterThan(QT_MAJOR_VERSION, 5)验证Qt的主版本大于5来添加子模块,但是Qt最新版本是5 .13.2不大于5,所以没有链接导致显示错误的模块。

In the tutorial greaterThan(QT_MAJOR_VERSION, 4): QT += widgets is used to support .pro so that it can be compiled for Qt4 and Qt5 since in the latter the widgets moved to a new sub-module called widgets.在教程greaterThan(QT_MAJOR_VERSION, 4): QT += widgets用于支持 .pro 以便它可以为 Qt4 和 Qt5 编译,因为在后者中,widgets 移动到一个名为 widgets 的新子模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM