Results 1 to 4 of 4

Thread: WaitOrbusyDialog not updating corrcetly even after process events

  1. #1
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default 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:-

    Main Window.cpp
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow),m_count(0)
    4. {
    5. ui->setupUi(this);
    6.  
    7. QThread* thread = new QThread;
    8. Worker* worker = new Worker();
    9. m_dialog = new WaitOrBusyDialog; //A custom class to busy dialog
    10.  
    11. worker->moveToThread(thread);
    12. connect(worker, SIGNAL(error(QString)), this, SLOT(errorString(QString)),Qt::QueuedConnection);
    13. connect(thread, SIGNAL(started()), worker, SLOT(process()),Qt::QueuedConnection);
    14. connect(worker,SIGNAL(showDialog()),this,SLOT(onDi alog()),Qt::QueuedConnection);
    15. connect(worker, SIGNAL(finished()), thread, SLOT(quit()),Qt::QueuedConnection);
    16. connect(worker, SIGNAL(finished()), worker, SLOT(deleteLater()),Qt::QueuedConnection);
    17. connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()),Qt::QueuedConnection);
    18. thread->start();
    19.  
    20. }
    21.  
    22. MainWindow::~MainWindow()
    23. {
    24. delete ui;
    25. }
    26.  
    27. void MainWindow::onDialog()
    28. {
    29. m_dialog->show();
    30. }
    To copy to clipboard, switch view to plain text mode 

    WorkerThread.cpp
    Qt Code:
    1. void Worker::process() {
    2. qApp->processEvents();
    3. int i=0;
    4. emit showDialog();
    5. while(i<10000)
    6. {
    7. qApp->processEvents();
    8. qDebug("Hello World!");
    9. i++;
    10. }
    11. emit finished();
    12. }
    To copy to clipboard, switch view to plain text mode 

    This is just a sample code to know simultanoeusly backgroud (debug output) and ui foreground process.The problem is why initially dialog hangs.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: WaitOrbusyDialog not updating corrcetly even after process events

    @anda
    After ignoring processevent still the dialog hangs.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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,
    _

Similar Threads

  1. Really need a way to process events!
    By hakermania in forum Qt Programming
    Replies: 2
    Last Post: 20th May 2011, 22:17
  2. ActiveQt out of process control sends no events
    By UweS in forum Qt Programming
    Replies: 0
    Last Post: 16th May 2011, 14:08
  3. Replies: 0
    Last Post: 6th August 2010, 11:01
  4. Pass custom events to another process
    By TTGator in forum Qt Programming
    Replies: 9
    Last Post: 14th January 2009, 22:02
  5. Replies: 1
    Last Post: 13th September 2008, 14:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.