各位大大:
小弟看过论坛上的常见问题#14
也照着做,以下是程式码:
标头档
- #ifndef BROWSER_H
- #define BROWSER_H
- #include <QtCore/QProcess>
- #include <QtCore/QThread>
- class Browser : public QThread
- {
- public:
- Browser();
- void run();
- void stop();
- QProcess *proc;
- };
- #endif // BROWSER_H
实作的程式码
- #include "browser.h"
- Browser::Browser()
- {}
- void Browser::run()
- {
- proc->execute("/mypath/QtAPP.exe");
- }
其中QtAPP.exe是一个用Qt编译出来的可执行档
是个有GUI的浏览器
呼叫该thread的程式码,也就是主程式
- class MainAPP : public QObject
- {
- ...
- ...
- Browser webThread;
- webThread.start(); // *** Wake browser up to work ***
- fprintf(stderr, "Called browser up...");
我的MainAPP是一个Qt的程式,没有GUI的那种console程式
呼叫到
webThread.start(); // *** Wake browser up to work ***
这行之后,我的主程式就卡住了
(但子thread叫出来的Browser则可以操作)
然后我把Browser关掉后,整个主程式也一起结束了(exited with code 0)
怎么会用了thread还把主程式卡住啊???
请各位大大帮忙看看,谢谢啊~
PS:刚找到繁体转简体的工具,但有些这边的用语不是很熟还请大大们海涵
[ 此帖被rr_tw在2010-04-19 15:42重新编辑 ]