MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow),m_count(0)
{
ui->setupUi(this);
Worker* worker = new Worker();
m_dialog = new WaitOrBusyDialog; //A custom class to busy dialog
worker->moveToThread(thread);
connect(worker,
SIGNAL(error
(QString)),
this,
SLOT(errorString
(QString)),Qt
::QueuedConnection);
connect(thread, SIGNAL(started()), worker, SLOT(process()),Qt::QueuedConnection);
connect(worker,SIGNAL(showDialog()),this,SLOT(onDi alog()),Qt::QueuedConnection);
connect(worker, SIGNAL(finished()), thread, SLOT(quit()),Qt::QueuedConnection);
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()),Qt::QueuedConnection);
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()),Qt::QueuedConnection);
thread->start();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onDialog()
{
m_dialog->show();
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow),m_count(0)
{
ui->setupUi(this);
QThread* thread = new QThread;
Worker* worker = new Worker();
m_dialog = new WaitOrBusyDialog; //A custom class to busy dialog
worker->moveToThread(thread);
connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString)),Qt::QueuedConnection);
connect(thread, SIGNAL(started()), worker, SLOT(process()),Qt::QueuedConnection);
connect(worker,SIGNAL(showDialog()),this,SLOT(onDi alog()),Qt::QueuedConnection);
connect(worker, SIGNAL(finished()), thread, SLOT(quit()),Qt::QueuedConnection);
connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()),Qt::QueuedConnection);
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()),Qt::QueuedConnection);
thread->start();
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::onDialog()
{
m_dialog->show();
}
To copy to clipboard, switch view to plain text mode
void Worker::process() {
qApp->processEvents();
int i=0;
emit showDialog();
while(i<10000)
{
qApp->processEvents();
qDebug("Hello World!");
i++;
}
emit finished();
}
void Worker::process() {
qApp->processEvents();
int i=0;
emit showDialog();
while(i<10000)
{
qApp->processEvents();
qDebug("Hello World!");
i++;
}
emit finished();
}
To copy to clipboard, switch view to plain text mode
Bookmarks