Qt线程的简单使用(二)——通过继承QThread()创建线程

Qt 中的线程的创建除了使用QObject::moveToThread()的函数以外,继承QThread(),重写其run()函数也是一种常见的方式.Qt 助手中,关于QThread的介绍中,有这样一段代码:

 1 class AdvancedThreadManager : public QThread
 2  {
 3  protected:
 4      void run()
 5      {
 6          /* ... other code to initialize thread... */
 7 
 8          // Begin event handling
 9          exec();
10      }
11  };

注意一点,这里需要显式调用exec。

posted @ 2017-03-30 21:37  gongchao1212  阅读(1764)  评论(0编辑  收藏  举报