#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)中更新数据
在void paintEvent(QPaintEvent *event)中动态显示数据
#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)中更新数据
在void paintEvent(QPaintEvent *event)中动态显示数据
#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)中更新数据
在void paintEvent(QPaintEvent *event)中动态显示数据.
#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)中更新数据
在void paintEvent(QPaintEvent *event)中动态显示数据.