WaitOrbusyDialog not updating corrcetly even after process events
Hi,
I did a sample test for learning thread.I have the follwoing code but for saome reson the wait or busy dialog does not run properly.I have attached a video where you can see dialog initialize hangs https://youtu.be/mjpnrLUx1VI.Here is the sample code:-
Code:
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();
}
Code:
void Worker::process() {
qApp->processEvents();
int i=0;
emit showDialog();
while(i<10000)
{
qApp->processEvents();
qDebug("Hello World!");
i++;
}
emit finished();
}
This is just a sample code to know simultanoeusly backgroud (debug output) and ui foreground process.The problem is why initially dialog hangs.
Re: WaitOrbusyDialog not updating corrcetly even after process events
Don't call qApp->processEvents() in the worker.
It runs in a different thread than the main event loop.
There is also no need to call processEvent(), the main thread doesn't do anything other then event processing.
Cheers,
_
Re: WaitOrbusyDialog not updating corrcetly even after process events
@anda
After ignoring processevent still the dialog hangs.
Re: WaitOrbusyDialog not updating corrcetly even after process events
Maybe something else blocking the main thread.
Have you tried without starting the thread, e.g. just calling onDialog() using QTimer::singleShot()?
Cheers,
_