进度条:
代码如下:
#include <QtGui/QApplication> #include <QProgressBar> #include <QThreadPool> #include <QTest> #include <QtCore> class RunnableTask : public QRunnable { public: RunnableTask(QProgressBar* progressBar) { m_ProgressBar = progressBar; } void run() { for (int i = 1; i <= 100; i++) { QMetaObject::invokeMethod(m_ProgressBar, "setValue", Qt::QueuedConnection, Q_ARG(int, i)); QTest::qSleep(100); qDebug() << "testRunable" << i << "% " << QThread::currentThread() << endl; } } private: QProgressBar* m_ProgressBar; }; int main(int argc, char *argv[]) { QApplication a(argc, argv); QProgressBar progressBar; progressBar.setValue(50); progressBar.show(); RunnableTask* task = new RunnableTask(&progressBar); QThreadPool::globalInstance()->start(task); return a.exec(); }