gpt4 book ai didi

c++ - 编译并运行Qt程序

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:20:14 24 4
gpt4 key购买 nike

我是 Qt 的新手,正在尝试编译和运行我从 Programming with Qt 一书中输入的 Qt 程序:

#include <qapplication.h>
#include <qlabel.h>
int main(int argc, char *argv[])
{
QApplication myapp(argc, argv);
QLabel *mylabel = new QLabel("Hello",0);
mylabel->resize(120,30);
myapp.setMainWidget(mylabel);
mylabel->show();
return myapp.exec();
}

当我执行此操作时:C:\Qt\2010.05\qt>gcc label.ccQt 命令提示符 上,我得到以下信息:

label.cc:1:26: error: qapplication.h: No such file or directory
label.cc:2:20: error: qlabel.h: No such file or directory
label.cc: In function 'int main(int, char**)':
label.cc:5: error: 'QApplication' was not declared in this scope
label.cc:5: error: expected ';' before 'myapp'
label.cc:6: error: 'QLabel' was not declared in this scope
label.cc:6: error: 'mylabel' was not declared in this scope
label.cc:6: error: expected type-specifier before 'QLabel'
label.cc:6: error: expected ';' before 'QLabel'
label.cc:8: error: 'myapp' was not declared in this scope

这是为什么呢?我编译Qt程序的方法是否正确?

谢谢。

最佳答案

Qmake 可以像这样生成一些默认的项目文件:

qmake -project
qmake
make

第一行生成项目文件,第二行从项目文件生成makefile并构建项目。

关于c++ - 编译并运行Qt程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5455926/

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