qt 线程简单学习
时间:2016-03-27 20:55:37
收藏:0
阅读:269
- QThread线程,只需继承QThread类,并重载run方法,之后就可以使用了。
#ifndef THREAD_H #define THREAD_H #include <QThread> class Thread : public QThread { Q_OBJECT public: Thread() { } protected: void run() { //add code } }; #endif // THREAD_H
- 也可以继承QObject对象,然后在派生类中声明一个QThread对象,在使用QObject的moveToThread方法,再借助信号,槽机制就可以实现多线程了。
#ifndef THREAD_H #define THREAD_H #include <QThread> #include <QObject> class Thread : public QObject { Q_OBJECT public: Thread() { this->moveToThread(&thread); thread.start(); } private: QThread thread; }; #endif // THREAD_H
原文:http://www.cnblogs.com/jecyhw/p/5326738.html
评论(0)