findumars

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

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

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

void stop() {
stopped = true;
}

private:
volatile bool stopped;
QString name;
};

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

Thread thread;
thread.start();
Thread thread1("Thread1");
thread1.start();
Thread thread2("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)中动态显示数据.

 

http://www.cppblog.com/biao/archive/2008/03/21/45053.html

分类:

技术点:

相关文章:

  • 2021-07-01
  • 2022-12-23
  • 2021-11-22
  • 2021-05-29
  • 2021-12-24
  • 2021-07-07
  • 2021-06-26
  • 2021-12-19
猜你喜欢
  • 2021-11-29
  • 2021-06-17
  • 2021-07-02
  • 2022-12-23
相关资源
相似解决方案