qt4-thread
class HelloThread : public QThread { Q_OBJECT private: void run(); };
void HelloThread::run() { qDebug() << "hello from worker thread " << thread()->currentThreadId(); }
int main(int argc, char *argv[]) { QCoreApplication app(argc, argv); HelloThread thread; thread.start(); qDebug() << "hello from GUI thread " << app.thread()->currentThreadId(); thread.wait(); return 0; }
|
等待唤醒
QWaitCondition m_wait; QMutex m_mutex;
m_mutex.lock(); ... m_wait.wait(&m_mutex); m_mutex.unlock();
m_wait.wakeOne();
|
同步
QMutex mutex; void someMethod() { QMutexLocker locker(&mutex); qDebug()<<"Hello"; qDebug()<<"World"; }
|
更新UI