class AnotherThread: public QThread{ Q_OBJECTsignals: void valueChanged(int);public: AnotherThread(QObject *parent, int val) : QThread(parent), m_currentVal(val) { }protected: virtual void run() { for (int i = 0; i < m_currentVal; ++i) emit valueChanged(i); }private: int m_currentVal;};class MainWindow:public QMainWindow{ Q_OBJECTpublic: MainWindow::MainWindow(QWidget *parent = 0) : QMainWindow(parent) { QHBoxLayout *mainLayout = new QHBoxLayout(); m_pbProgress = new QProgressBar(); m_pbProgress->setMinimum(0); m_pbProgress->setMaximum(100); m_at = new AnotherThread(this, m_pbProgress->maximum()); connect(m_at, SIGNAL(valueChanged(int)), m_pbProgress, SLOT(setValue(int))); QPushButton *pbRun = new QPushButton("Run"); connect(pbRun, SIGNAL(clicked()), m_at, SLOT(start())); mainLayout->addWidget(m_pbProgress); mainLayout->addWidget(pbRun); QWidget *central = new QWidget(); central->setLayout(mainLayout); setCentralWidget(central); }private: QProgressBar *m_pbProgress; AnotherThread *m_at;};
connect(m_at, SIGNAL(valueChanged(int)), m_pbProgress, SLOT(setValue(int)));
connect(m_at, SIGNAL(valueChanged(int)), m_pbProgress, SLOT(setValue(int)), Qt::QueuedConnection);
if ((c->type == Qt::AutoConnection && (currentThreadData != sender->d_func()->threadData || c->receiver->d_func()->threadData != sender->d_func()->threadData)) || (c->type == Qt::QueuedConnection)) {