热门标签 | HotTags
当前位置:  开发笔记 > 开发工具 > 正文

使用Qt,KDevelopDesigner开发Linux的图形界面

使用Qt,KDevelopDesigner开发Linux的图形界面--Linux通用技术-Linux编程与内核信息,下面是详情阅读。
用Qt 来生成图形界面,一种方法是使用KDevelop Designer来设计界面,用命令行编译和运行;另外一种方法是用Qt3 Designer来设计界面,用KDevelop: C/C++或者KDevelop:KDE/C++来编译和运行,示例完整过程如下:

1,打开KDevelop Designer
2,File--->New--->Main Window,使用默认设置。
3,保存到/root/qt目录面。
4,
[root@localhost qt]# ll
-rw-r--r-- 1 root root 18452 Oct 9 13:49 form2.ui
[root@localhost qt]#touch hello.cpp
[root@localhost qt]#vim hello.cpp
[root@localhost qt]#cat hello.cpp
#include
#include
#include

main(int argc,char *argv[])
{

QApplication app(argc,argv);
Form2 *fr = new Form2;
fr->show();
app.setMainWidget(fr);
return app.exec();
}
[root@localhost qt]# qmake -project
[root@localhost qt]# ll
total 40
-rw-r--r-- 1 root root 18452 Oct 9 13:49 form2.ui
-rw-r--r-- 1 root root 219 Oct 9 13:57 hello.cpp
-rw-r--r-- 1 root root 309 Oct 9 13:59 qt.pro
[root@localhost qt]# mv qt.pro hello.pro
[root@localhost qt]# ll
total 40
-rw-r--r-- 1 root root 18452 Oct 9 13:49 form2.ui
-rw-r--r-- 1 root root 219 Oct 9 13:57 hello.cpp
-rw-r--r-- 1 root root 309 Oct 9 13:59 hello.pro
[root@localhost qt]# qmake
[root@localhost qt]# ll
-rw-r--r-- 1 root root 18452 Oct 9 13:49 form2.ui
-rw-r--r-- 1 root root 219 Oct 9 13:57 hello.cpp
-rw-r--r-- 1 root root 309 Oct 9 13:59 hello.pro
-rw-r--r-- 1 root root 2076 Oct 9 13:59 form2.h
-rw-r--r-- 1 root root 3402 Oct 9 13:59 Makefile

qmake命令生成form2.h头文件,在此文件中有Form2类的声明

[root@localhost qt]# make
[root@localhost qt]# ll
total 940
-rw-r--r-- 1 root root 29531 Oct 9 13:59 form2.cpp
-rw-r--r-- 1 root root 2076 Oct 9 13:59 form2.h
-rw-r--r-- 1 root root 188712 Oct 9 13:59 form2.o
-rw-r--r-- 1 root root 18452 Oct 9 13:49 form2.ui
-rwxr-xr-x 1 root root 321718 Oct 9 14:00 hello
-rw-r--r-- 1 root root 219 Oct 9 13:57 hello.cpp
-rw-r--r-- 1 root root 109088 Oct 9 13:59 hello.o
-rw-r--r-- 1 root root 309 Oct 9 13:59 hello.pro
-rw-r--r-- 1 root root 3402 Oct 9 13:59 Makefile
-rw-r--r-- 1 root root 4721 Oct 9 13:59 moc_form2.cpp
-rw-r--r-- 1 root root 193144 Oct 9 14:00 moc_form2.o
[root@localhost qt]# ./hello 运行即可看到图形界面。

示例二:hello world图形窗口,
[root@localhost ~]# mkdir /tmp/feifei
[root@localhost ~]# cd /tmp/feifei
[root@localhost feifei]touch hello.cpp
[root@localhost feifei]qmake -project
[root@localhost feifei]mv qt.pro hello.pro
[root@localhost feifei]qmake
[root@localhost feifei]make
[root@localhost feifei]./hello 运行即可看到图形界面

[root@localhost feifei]# ll
总计 176
-rwxr-xr-x 1 root root 71883 10-09 13:35 hello
-rw-r--r-- 1 root root 227 10-09 13:34 hello.cpp
-rw-r--r-- 1 root root 83532 10-09 13:35 hello.o
-rw-r--r-- 1 root root 286 10-09 13:31 hello.pro
-rw-r--r-- 1 root root 2983 10-09 13:34 Makefile
[root@localhost feifei]# cat hello.cpp
#include
#include

int main(int argc, char *argv[])
{
QApplication app(argc,argv);
QLabel *label = new QLabel ("Hello worl!", 0 );
app.setMainWidget (label);
label->show();
return app.exec();
}
[root@localhost feifei]#

示例三:通过KDevelop : KDE/C++ 来编译和运行:
1,打开Qt3 Designer
2,File--->New--->C++ project,保存到/root/qt2
3,File--->New--->C++ Main File(main.cpp),按照默认设置保存,此时可以打开main.cpp编辑页面。
4,打开KDevelop: KDE/C++
5,Project-->Import exiting project,选择刚刚保存的目录/root/qt2确认
6,Build--->Build project,
7,Build--->Execute Main program,运行即可看到图形界面。

注:此方式只适合于Qt3 Designer, KDevelop Designer不可以,但是可以配置使得它支持C++编辑。

相应的提示信息如下:
There is no plugin for editing C++ code installed.
Note:Plugins are not available in static Qt configurations.

以上在Qt3,Qt4上都测试通过,更多可以参考《C++ GUI QT3编程》。
推荐阅读
author-avatar
拍友2502916683
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有