久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

帶有 movetothread 的 qt 線程

qt thread with movetothread(帶有 movetothread 的 qt 線程)
本文介紹了帶有 movetothread 的 qt 線程的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我正在嘗試使用線程創(chuàng)建程序:主要以一個(gè)循環(huán)開始.當(dāng)測(cè)試返回 true 時(shí),我創(chuàng)建一個(gè)對(duì)象,并希望該對(duì)象在另一個(gè)線程中工作然后返回并開始測(cè)試.

I'm trying to create a program using threads: the main start with a loop. When a test returns true, I create an object and I want that object to work in an other thread then return and start the test .

QCoreApplication a(argc, argv);
while(true){
    Cmd cmd;
    cmd =db->select(cmd);
    if(cmd.isNull()){ 
        sleep(2);  
        continue ;
    }
    QThread *thread = new QThread( );
    process *class= new process ();
    class->moveToThread(thread);
    thread->start();

    qDebug() << " msg"; // this doesn't run until  class finish it's work 
}
return a.exec();

問(wèn)題是當(dāng)我啟動(dòng)新線程時(shí),主線程停止并等待新線程完成.

the problem is when i start the new thread the main thread stops and wait for the new thread's finish .

推薦答案

規(guī)范的 Qt 方式如下所示:

The canonical Qt way would look like this:

 QThread* thread = new QThread( );
 Task* task = new Task();

 // move the task object to the thread BEFORE connecting any signal/slots
 task->moveToThread(thread);

 connect(thread, SIGNAL(started()), task, SLOT(doWork()));
 connect(task, SIGNAL(workFinished()), thread, SLOT(quit()));

 // automatically delete thread and task object when work is done:
 connect(task, SIGNAL(workFinished()), task, SLOT(deleteLater()));
 connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));

 thread->start();

如果您不熟悉信號(hào)/插槽,Task 類將如下所示:

in case you arent familiar with signals/slots, the Task class would look something like this:

class Task : public QObject
{
Q_OBJECT
public:
    Task();
    ~Task();
public slots:
    // doWork must emit workFinished when it is done.
    void doWork();
signals:
    void workFinished();
};

這篇關(guān)于帶有 movetothread 的 qt 線程的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 毛片链接 | 国产亚洲精品综合一区 | 亚洲精品日韩一区二区电影 | 成人av网站在线观看 | 一区二区av| 欧美一页 | www.日本精品| 国产精品美女www爽爽爽视频 | 国产激情在线观看 | 香蕉一区 | 中文字幕人成乱码在线观看 | 人人人干 | 91精品久久久久久久久 | 国产一区二区三区精品久久久 | 成人动漫一区二区 | 黄网站涩免费蜜桃网站 | 久久精品久久久久久 | 色婷婷av777| 久久狠狠 | 91精品国产综合久久久密闭 | 国产专区在线 | 日韩成人精品一区 | 日本久久网 | 男女羞羞视频网站 | 国产小u女发育末成年 | 亚洲人精品午夜 | 日韩中文字幕 | 在线观看国产视频 | 精品av| 亚洲乱码一区二区三区在线观看 | 国产精品成av人在线视午夜片 | 久久久久久久国产精品 | 91麻豆精品国产91久久久久久 | 亚洲精品一区二区三区蜜桃久 | 97操操| 亚洲欧洲精品成人久久奇米网 | 国产一区二区三区色淫影院 | 免费视频一区二区 | 天堂亚洲 | 日本亚洲欧美 | 亚洲成人免费在线 |