gpt4 book ai didi

c++ - 尝试运行 "Hello, world!"桌面应用程序 QT 时出现多个错误

转载 作者:行者123 更新时间:2023-11-27 23:48:49 24 4
gpt4 key购买 nike

我正在尝试开始使用 QT。具体来说,“你好,世界!”本基础教程中的桌面应用程序:Getting Started on the Commandline

.cpp 文件名为 helloX.cpp,内容如下:

#include <QtGui>

int main(int argc, char **argv) {
QApplication app(argc, argv);
QLabel label("Hello, world!");
label.show();
return app.exec();
}

这是我在运行 make 时遇到的大量错误,但我在任何地方都找不到对这些错误的任何引用!任何帮助故障排除将不胜感激。

/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -O2 -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -mmacosx-version-min=10.9 -Wall -W -fPIC -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I. -I. -I/Users/hassanshallal/anaconda/include/qt -I/Users/hassanshallal/anaconda/include/qt/QtGui -I/Users/hassanshallal/anaconda/include/qt/QtCore -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/AGL.framework/Headers -I/Users/hassanshallal/anaconda/mkspecs/macx-clang -o helloX.o helloX.cpp
helloX.cpp:4:15: error: variable has incomplete type 'QApplication'
QApplication app(argc, argv);
^
/Users/hassanshallal/anaconda/include/qt/QtCore/qobject.h:452:18: note: forward declaration of
'QApplication'
friend class QApplication;
^
helloX.cpp:5:2: error: use of undeclared identifier 'QLabel'; did you mean 'QAccessible::Label'?
QLabel label("Hello, world!");
^~~~~~
QAccessible::Label
/Users/hassanshallal/anaconda/include/qt/QtGui/qaccessible.h:360:9: note: 'QAccessible::Label' declared
here
Label = 0x00000001,
^
helloX.cpp:5:8: error: expected ';' after expression
QLabel label("Hello, world!");
^
;
helloX.cpp:5:9: error: use of undeclared identifier 'label'
QLabel label("Hello, world!");
^
helloX.cpp:6:2: error: use of undeclared identifier 'label'
label.show();
^
helloX.cpp:5:2: warning: expression result unused [-Wunused-value]
QLabel label("Hello, world!");
^~~~~~
1 warning and 5 errors generated.
make: *** [helloX.o] Error 1

非常感谢

最佳答案

  1. qmake 应该在您的路径中。在终端做 export PATH=<path to qmake exe>;$PATH

  2. 您需要按照教程中的说明正确设置 .pro 文件。

    2a。与 INCLUDE+=为 qt header 添加正确的包含路径

    2b。与 Qt+=添加您要使用的库。对于您的简单示例,guiwidget 应该没问题。

  3. 转到您的项目根目录并运行 qmakema​​ke,如您所引用的教程中所述。

  4. 不要忘记为您在应用中使用的每个小部件(如 QApplication、QLabel 等)包含 header 。

关于c++ - 尝试运行 "Hello, world!"桌面应用程序 QT 时出现多个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48390077/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com