C++ “尝试运行时出现多个错误”;你好,世界&引用;桌面应用程序
我正在尝试开始使用QT。特别是本基础教程中的“Hello,world!”桌面应用程序: .cpp文件名为helloX.cpp,包含以下内容:C++ “尝试运行时出现多个错误”;你好,世界&引用;桌面应用程序,c++,qt,C++,Qt,我正在尝试开始使用QT。特别是本基础教程中的“Hello,world!”桌面应用程序: .cpp文件名为helloX.cpp,包含以下内容: #include <QtGui> int main(int argc, char **argv) { QApplication app(argc, argv); QLabel label("Hello, world!"); label.show(); return app.exec(); } 非常感谢您需要确保您的Qt应用程序具有正
#include <QtGui>
int main(int argc, char **argv) {
QApplication app(argc, argv);
QLabel label("Hello, world!");
label.show();
return app.exec();
}
非常感谢您需要确保您的Qt应用程序具有正确的包含文件,并且您的构建环境可以查看并链接到所有Qt库。这些错误是因为编译器找不到正在使用的qtapi
export PATH=$路径
INCLUDE+=
为qt头添加正确的INCLUDE路径
2b。使用Qt+=
添加要使用的库。对于您的简单示例,gui和小部件应该可以非常感谢您的反馈。事实证明,我所需要的只是以下内容:
1) add #include <QApplication> to the .cpp file
2) add #include <QLabel> to the .cpp file
3) add: QT += widgets to the .pro file
1)将#include添加到.cpp文件中
2) 将#include添加到.cpp文件
3) 将:QT+=小部件添加到.pro文件
这解决了所有的问题
最好是显示您的代码。您是否忘记了一个
#include
?似乎缺少qt库QApplication和QLabel附带的QtGui!您的.pro
文件中有什么?您好,谢谢您的逐步回答:1)终端上的qmake-v使用Qt version 5.6.2在/Users/hassanshallal/anaconda/lib中计算为:qmake version 3.0,表明qmake在我的路径中。我运行qmake没有问题。2) qmake-project和qmake运行时没有问题,上面的输出是我运行make之后的输出。在cpp文件的顶部执行#include和#include我刚刚执行了这个操作,运行了qmake-project、qmake和make。出现了其他问题:架构x86_64的未定义符号:“QApplication::exec()”,“QApplication::QApplication(int&,char**,int)”,“QApplication::~QApplication()”,“QLabel::QLabel(QString const&,QWidget*,QFlags)”,“QLabel::~QLabel(),“QWidget::show()”,引用自:helloX.o ld:symbol中的找不到体系结构x86_64 clang:错误:链接器命令失败,退出代码为1(使用-v查看调用)make:**[helloX.app/Contents/MacOS/helloX]错误1尝试在32位模式下编译。获取qt creator,打开一些示例项目并查看其配置。感谢StPiere,事实证明我需要将qt+=小部件添加到.pro文件中。
1) add #include <QApplication> to the .cpp file
2) add #include <QLabel> to the .cpp file
3) add: QT += widgets to the .pro file