独立线程中实现QT GUI
在网上搜集的资料:
http://www.qtcentre.org/threads/16552-Starting-QT-GUI-in-a-seperate-Thread
http://stackoverflow.com/questions/16812602/qt-main-gui-and-other-thread-events-loops
http://stackoverflow.com/questions/9777911/how-do-i-create-a-window-in-different-qt-threads
http://stackoverflow.com/questions/16501284/qt-updating-main-window-with-second-thread
据这些资料看,在非主线程中处理QT或多或少都会有些问题,但我在文档里倒是没有明确找到说QApplication一定要定义在主线程中。
所以下面尝试了一下:
#include <windows.h>
#include <process.h> /* _beginthread, _endthread */
#include <stdlib.h>
#include <QtGui/QApplication>
#include <QtGui/QPushButton> void initUI(void* dummy) {
int argc = ;
QApplication app(argc, NULL);
QPushButton button("Hello, world");
button.show();
app.exec();
printf("gui thread dead.\n");
_endthread();
} int main(int argc, char** argv)
{
/* Launch gui thread. */
_beginthread( initUI, , NULL ); /* Do something with main thread */
while(){
printf("tick ...\n"); Sleep();
}
}
运行结果来看似乎并没有多少问题:
后续再看。
----------------附:PYQT编译步骤----------------
1. 下载QT library for windows并安装(C:/QT/4.8.5),并将C:/QT/4.8.5/bin目录添加到系统环境变量中(后续编译依赖qt的qmake):
http://download.qt-project.org/official_releases/qt/4.8/4.8.5/qt-win-opensource-4.8.5-vs2010.exe
2. 下载PYQT source package并解压(C:/PyQt-win-gpl-4.10.3)
http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.10.3/PyQt-win-gpl-4.10.3.zip
3. 下载SIP source package并解压(C:/sip-4.15.4)
http://sourceforge.net/projects/pyqt/files/sip/sip-4.15.4/sip-4.15.4.zip
4. 在VS2010的命令提示行环境下执行(编译sip并安装pyd至python目录):
cd c:/sip-4.15.
python configure.py
nmake
nmake install
5. 在VS2010的命令提示行环境下执行(编译pyqt):
cd c:/pyqt-win-gpl-4.10.
python configure-np.py
nmake
nmake install
6. 在python解释器中测试:
>>> import sipconfig #测试sip
>>> from PyQt4.QT import * #测试pyqt
最新文章
- ASP.NET MVC 5 Web编程3 -- Controller的应用及扩展
- JDK的安装与配置以及eclipse的使用
- centos7 install 安装mysql
- if_nametoindex可以检查网卡名称是否有效
- Mathematics:GCD &; LCM Inverse(POJ 2429)
- Evolutionary Computing: 2. Genetic Algorithm(1)
- CSS计数器的趣味时光
- SQL逻辑读变成零
- cocos引擎v2.1版本android 编译问题解决办法 (cocos2d-x-3.4rc1)
- 纯蓝ICON_学习教程
- 前端JS基础知识
- 如何查看jar包的版本号?(转)
- windows下配置下burpsuite的小方法。
- C#分部类型解析
- 分解质因数FZU - 1075
- react编译报错:Import in body of module; reorder to top import/first
- Spring boot+Thymeleaf+easyui集成:js创建组件页面报错
- sqrt()函数对素数判断的优化
- 《Inside C#》笔记(十一) 运算符重载
- C#中类为什么要实例化
热门文章
- log4net 总结
- 如何去掉&#160;Discuz标题后缀power&#160;by&#160;discuz
- switch...case 和 if...else
- Android开发(一):环境搭建
- java连接mysql数据库(jsp显示和控制台显示)
- [BZOJ 2212] [Poi2011] Tree Rotations 【线段树合并】
- 由abcd四个字符取5个作允许重复的排列,要求a出现次数不超过2次,但不能不出现;b不超过1个;c不超过3个;d出现的次数为偶数。求满足以上条件的排列数。
- Ubuntu下与菜单和图标相关的几个文件夹
- 1090-Rock, Paper, Scissors
- codevs 版刷计划(1000-1099)