#include <QApplication> #include <QThread> #include <QMainWindow> #include <qprogressbar># Include <qpushbutton>class Renderthread:public qthread{q_objectsignals:void notify (int);p ublic: Renderthread (Qobject *parent = 0): Qthread (parent) {}; void Test () {start (highestpriority); };p rotected:void Run () {int i = 0; while (i<101) {msleep (50); i++; Emit notify (i); } };}; Class Mainwindow:public qmainwindow{Q_objectpublic:mainwindow (qwidget *parent = 0) {Resize (600, 400); Centralwidget = new Qwidget (this); ProgressBar = new Qprogressbar (centralwidget); Progressbar->setgeometry (Qrect (130, 180, 321, 23)); Progressbar->setvalue (0); pushbutton = new Qpushbutton ("Test", centralwidget); Pushbutton->setgeometry (Qrect (110, 100, 75, 23)); Qobject::connect (pushbutton, SIGNAL (clicked ()), this, SLOT (onclicked ())); This->setcentralwidget (Centralwidget); }; ~mainwindow () {};p Rivate:qprogressbar *progressbar; Qpushbutton *pushbutton; Qwidget *centralwidget; Renderthread render;public slots:void onclicked () {Connect (&render,signal (notify (int)), This,slot (Onnoti FY (int))); Render.test (); }; void onnotify (int i) {progressbar->setvalue (i); };}; #include "Test.moc" int main (int argc,char* argv[]) {qapplication app (ARGC,ARGV); MainWindow window; Window.show (); return app.exec ();}
http://blog.csdn.net/tingsking18/article/details/5096172
"Go" QT Multi-threaded interface---update Qprogressbar in Qthread