使用Qt,KDevelopDesigner开发Linux的图形界面
作者:拍友2502916683 | 来源:互联网 | 2017-07-24 09:37
使用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编程》。
推荐阅读
-
本文详细介绍了 Dockerfile 的编写方法及其在网络配置中的应用,涵盖基础指令、镜像构建与发布流程,并深入探讨了 Docker 的默认网络、容器互联及自定义网络的实现。 ...
[详细]
蜡笔小新 2024-12-27 17:31:41
-
本文详细介绍如何使用Samba软件配置CIFS文件共享服务,涵盖安装、配置、权限管理及多用户挂载等关键步骤。通过具体示例和命令行操作,帮助读者快速搭建并优化Samba服务器。 ...
[详细]
蜡笔小新 2024-12-26 17:44:08
-
-
本文详细介绍了如何规划和部署一个高可用的Etcd集群,包括主机配置、软件安装、防火墙设置及集群健康检查等内容。通过合理的硬件配置和网络规划,确保Etcd集群在生产环境中的稳定运行。 ...
[详细]
蜡笔小新 2024-12-23 15:20:17
-
在成功安装和测试MySQL及Apache之后,接下来的步骤是安装PHP。为了确保安全性和配置的一致性,建议在安装PHP前先停止MySQL和Apache服务,并将MySQL集成到PHP中。 ...
[详细]
蜡笔小新 2024-12-23 13:08:12
-
本实验旨在通过配置 Nginx 实现反向代理和负载均衡,确保从北京本地代理服务器访问上海的 Web 服务器时,能够依次显示红、黄、绿三种颜色页面以验证负载均衡效果。 ...
[详细]
蜡笔小新 2024-12-22 15:15:48
-
本文详细介绍了Vim编辑器的三种主要模式及其常用命令,帮助用户更好地掌握这一强大的文本编辑工具。 ...
[详细]
蜡笔小新 2024-12-22 13:43:58
-
本文详细介绍了如何为嵌入式应用开发搭建必要的软硬件环境,并提供了通过串口和网线两种方式将文件传输到开发板的具体步骤。适合Linux开发初学者参考。 ...
[详细]
蜡笔小新 2024-12-22 13:38:48
-
本文详细介绍了EasyReport,一个易于使用的开源Web报表工具。该工具支持Hadoop、HBase及多种关系型数据库,能够将SQL查询结果转换为HTML表格,并提供Excel导出、图表显示和表头冻结等功能。 ...
[详细]
蜡笔小新 2024-12-22 11:11:28
-
本文详细介绍如何在Fedora 31操作系统上安装和配置PostgreSQL 12数据库。包括环境准备、安装步骤、配置优化以及安全设置,确保数据库能够稳定运行并提供高效的性能。 ...
[详细]
蜡笔小新 2024-12-21 15:37:13
-
本文探讨了如何在Classic ASP中实现与PHP的hash_hmac('SHA256', $message, pack('H*', $secret))函数等效的哈希生成方法。通过分析不同实现方式及其产生的差异,提供了一种使用Microsoft .NET Framework的解决方案。 ...
[详细]
蜡笔小新 2024-12-21 10:38:09
-
本文详细介绍了如何在云服务器上配置Nginx、Tomcat、JDK和MySQL。涵盖从下载、安装到配置的完整步骤,帮助读者快速搭建Java Web开发环境。 ...
[详细]
蜡笔小新 2024-12-21 10:18:56
-
本文将详细介绍如何在没有显示器的情况下,使用Raspberry Pi Imager为树莓派4B安装操作系统,并进行基本配置,包括设置SSH、WiFi连接以及更新软件源。 ...
[详细]
蜡笔小新 2024-12-21 08:14:50
-
本文旨在提供一套详细的步骤,指导读者如何在CentOS 7.6操作系统上成功安装和配置Prometheus 2.17.1及Grafana 6.7.2-1,实现高效的数据监控与可视化。 ...
[详细]
蜡笔小新 2024-12-20 10:05:02
-
本文介绍了在MacOS上通过Homebrew安装Anaconda3,并配置环境变量以实现不同Python版本之间的快速切换。同时,提供了详细的步骤来创建和管理多个Python环境。 ...
[详细]
蜡笔小新 2024-12-19 13:24:19
-
请看|间隔时间_Postgresql 主从复制 ...
[详细]
蜡笔小新 2024-12-19 03:24:54
-
拍友2502916683
这个家伙很懒,什么也没留下!