#include#include#includeclassThread:publicQThread{public:Thread(QStringname=""){stopped=false;this->name=name;}voidrun(){while(!stopped){std::cout<<"In"<

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Qt多線(xiàn)程編程實(shí)例

系統(tǒng) 2391 0

#include < iostream >
#include
< QApplication >
#include
< QThread >
#include
< QString >

class Thread: public QThread {
public :
Thread(QStringname
= "" ) {
stopped
= false ;
this -> name = name;
}


void run() {
while ( ! stopped) {
std::cout
<< " In " << name.toStdString() << " 'srun(). " << std::endl;
QThread::msleep(
400 );
}

}


void stop() {
stopped
= true ;
}


private :
volatile boolstopped;
QStringname;
}
;

int main( int argc, char * argv[]) {
QApplicationapp(argc,argv);

Threadthread;
thread.start();
Threadthread1(
" Thread1 " );
thread1.start();
Threadthread2(
" Thread2 " );
thread2.start();

return app.exec();
}


在Widget中, 還可以使用如在繼承自QObject 的 void showEvent(QShowEVent *event)中使用myTimerId = startTimer();
在void hideEvent(QHideEVent *event)中使用killTimer(myTimerId);
在void timerEvent(QTimerEvent *event)中更新數(shù)據(jù)
在void paintEvent(QPaintEvent *event)中動(dòng)態(tài)顯示數(shù)據(jù)
#include < iostream >
#include
< QApplication >
#include
< QThread >
#include
< QString >

class Thread: public QThread {
public :
Thread(QStringname
= "" ) {
stopped
= false ;
this -> name = name;
}


void run() {
while ( ! stopped) {
std::cout
<< " In " << name.toStdString() << " 'srun(). " << std::endl;
QThread::msleep(
400 );
}

}


void stop() {
stopped
= true ;
}


private :
volatile boolstopped;
QStringname;
}
;

int main( int argc, char * argv[]) {
QApplicationapp(argc,argv);

Threadthread;
thread.start();
Threadthread1(
" Thread1 " );
thread1.start();
Threadthread2(
" Thread2 " );
thread2.start();

return app.exec();
}


在Widget中, 還可以使用如在繼承自QObject 的 void showEvent(QShowEVent *event)中使用myTimerId = startTimer();
在void hideEvent(QHideEVent *event)中使用killTimer(myTimerId);
在void timerEvent(QTimerEvent *event)中更新數(shù)據(jù)
在void paintEvent(QPaintEvent *event)中動(dòng)態(tài)顯示數(shù)據(jù).

Qt多線(xiàn)程編程實(shí)例


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 张家港市| 肥乡县| 文山县| 个旧市| 萨嘎县| 汤原县| 平利县| 英超| 四会市| 电白县| 安溪县| 恭城| 禄劝| 象州县| 远安县| 东至县| 泰州市| 辉县市| 丰台区| 咸宁市| 静海县| 巴彦淖尔市| 当阳市| 伊春市| 肃北| 滕州市| 玛曲县| 昆山市| 沙河市| 土默特右旗| 怀仁县| 周宁县| 罗城| 九龙坡区| 门源| 资中县| 米泉市| 卢氏县| 延川县| 漯河市| 黔西|