program a Qt demo
【摘要】
I assume that your environment is OK to program a Qt.By the way all code is done on Ubuntu. Step1: pro...
I assume that your environment is OK to program a Qt.By the way all code is done on Ubuntu.
Step1: program a Qt demo in QtProject folder.
#include <QApplication>
#include <QLabel>
#include <QWidget>
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
QLabel hello("<center>Welcome to my first Qt program</center>");
hello.setWindowTitle("My first Qt program");
hello.resize(400,400);
hello.show();
return app.exec();
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
To save above code in a file testmain.cpp.
Step2: generate a .pro
file which is used to generate a Makefile
~/QtProject$ qmake -project
~/QtProject$ ls
QtProject.pro testmain.cpp
- 1
- 2
- 3
Step3: add QT += gui widgets
to the end of QtProject.pro file.
Step4: to generate a Makefile
file which is used to compile the program.
~/QtProject$ qmake QtProject.pro
kyunban@kyunban:~/QtProject$ ls
Makefile QtProject.pro testmain.cpp
- 1
- 2
- 3
Step5: compile this program
~/QtProject$ make
~/QtProject$ ls
Makefile QtProject QtProject.pro testmain.cpp testmain.o
- 1
- 2
- 3
Finally, we get a executable file QtProject
,run it with below command:
~/QtProject$ ./QtProject
- 1
文章来源: blog.csdn.net,作者:WongKyunban,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/weixin_40763897/article/details/121724519
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)