在网上搜集的资料:

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

最新文章

  1. ASP.NET MVC 5 Web编程3 -- Controller的应用及扩展
  2. JDK的安装与配置以及eclipse的使用
  3. centos7 install 安装mysql
  4. if_nametoindex可以检查网卡名称是否有效
  5. Mathematics:GCD &amp; LCM Inverse(POJ 2429)
  6. Evolutionary Computing: 2. Genetic Algorithm(1)
  7. CSS计数器的趣味时光
  8. SQL逻辑读变成零
  9. cocos引擎v2.1版本android 编译问题解决办法 (cocos2d-x-3.4rc1)
  10. 纯蓝ICON_学习教程
  11. 前端JS基础知识
  12. 如何查看jar包的版本号?(转)
  13. windows下配置下burpsuite的小方法。
  14. C#分部类型解析
  15. 分解质因数FZU - 1075
  16. react编译报错:Import in body of module; reorder to top import/first
  17. Spring boot+Thymeleaf+easyui集成:js创建组件页面报错
  18. sqrt()函数对素数判断的优化
  19. 《Inside C#》笔记(十一) 运算符重载
  20. C#中类为什么要实例化

热门文章

  1. log4net 总结
  2. 如何去掉&#160;Discuz标题后缀power&#160;by&#160;discuz
  3. switch...case 和 if...else
  4. Android开发(一):环境搭建
  5. java连接mysql数据库(jsp显示和控制台显示)
  6. [BZOJ 2212] [Poi2011] Tree Rotations 【线段树合并】
  7. 由abcd四个字符取5个作允许重复的排列,要求a出现次数不超过2次,但不能不出现;b不超过1个;c不超过3个;d出现的次数为偶数。求满足以上条件的排列数。
  8. Ubuntu下与菜单和图标相关的几个文件夹
  9. 1090-Rock, Paper, Scissors
  10. codevs 版刷计划(1000-1099)