#include
<
iostream
>
#include < QApplication >
#include < QThread >
#include < QString >
class Thread: public QThread {
public:
Thread(QStringname=""){
stopped=false;
this->name=name;
}
voidrun(){
while(!stopped){
std::cout<<"In"<<name.toStdString()<<"'srun()."<<std::endl;
QThread::msleep(400);
}
}
voidstop(){
stopped=true;
}
private:
volatileboolstopped;
QStringname;
} ;
int main( int argc, char * argv[]) {
QApplicationapp(argc,argv);
Threadthread;
thread.start();
Threadthread1("Thread1");
thread1.start();
Threadthread2("Thread2");
thread2.start();
returnapp.exec();
}
在Widget中, 还可以使用如在继承自QObject 的 void showEvent(QShowEVent *event)中使用myTimerId = startTimer();
在void hideEvent(QHideEVent *event)中使用killTimer(myTimerId);
在void timerEvent(QTimerEvent *event)中更新数据
在void paintEvent(QPaintEvent *event)中动态显示数据
#include < QApplication >
#include < QThread >
#include < QString >
class Thread: public QThread {
public:
Thread(QStringname=""){
stopped=false;
this->name=name;
}
voidrun(){
while(!stopped){
std::cout<<"In"<<name.toStdString()<<"'srun()."<<std::endl;
QThread::msleep(400);
}
}
voidstop(){
stopped=true;
}
private:
volatileboolstopped;
QStringname;
} ;
int main( int argc, char * argv[]) {
QApplicationapp(argc,argv);
Threadthread;
thread.start();
Threadthread1("Thread1");
thread1.start();
Threadthread2("Thread2");
thread2.start();
returnapp.exec();
}
在Widget中, 还可以使用如在继承自QObject 的 void showEvent(QShowEVent *event)中使用myTimerId = startTimer();
在void hideEvent(QHideEVent *event)中使用killTimer(myTimerId);
在void timerEvent(QTimerEvent *event)中更新数据
在void paintEvent(QPaintEvent *event)中动态显示数据
#include
<
iostream
>
#include < QApplication >
#include < QThread >
#include < QString >
class Thread: public QThread {
public:
Thread(QStringname=""){
stopped=false;
this->name=name;
}
voidrun(){
while(!stopped){
std::cout<<"In"<<name.toStdString()<<"'srun()."<<std::endl;
QThread::msleep(400);
}
}
voidstop(){
stopped=true;
}
private:
volatileboolstopped;
QStringname;
} ;
int main( int argc, char * argv[]) {
QApplicationapp(argc,argv);
Threadthread;
thread.start();
Threadthread1("Thread1");
thread1.start();
Threadthread2("Thread2");
thread2.start();
returnapp.exec();
}
在Widget中, 还可以使用如在继承自QObject 的 void showEvent(QShowEVent *event)中使用myTimerId = startTimer();
在void hideEvent(QHideEVent *event)中使用killTimer(myTimerId);
在void timerEvent(QTimerEvent *event)中更新数据
在void paintEvent(QPaintEvent *event)中动态显示数据.
#include < QApplication >
#include < QThread >
#include < QString >
class Thread: public QThread {
public:
Thread(QStringname=""){
stopped=false;
this->name=name;
}
voidrun(){
while(!stopped){
std::cout<<"In"<<name.toStdString()<<"'srun()."<<std::endl;
QThread::msleep(400);
}
}
voidstop(){
stopped=true;
}
private:
volatileboolstopped;
QStringname;
} ;
int main( int argc, char * argv[]) {
QApplicationapp(argc,argv);
Threadthread;
thread.start();
Threadthread1("Thread1");
thread1.start();
Threadthread2("Thread2");
thread2.start();
returnapp.exec();
}
在Widget中, 还可以使用如在继承自QObject 的 void showEvent(QShowEVent *event)中使用myTimerId = startTimer();
在void hideEvent(QHideEVent *event)中使用killTimer(myTimerId);
在void timerEvent(QTimerEvent *event)中更新数据
在void paintEvent(QPaintEvent *event)中动态显示数据.