How to update status bar during lengthy computations



  • In my desktop application I would like to update text in a status bar during lengthy computations. I do know about Progress Bar, but my needs are different. I also read "the applicable article":http://doc.qt.digia.com/qq/qq27-responsive-guis.html and came up with simple code:

    @void mainwindow::setStatusText(QString text) {
    statusBar()->showMessage(text);
    QCoreApplication::sendPostedEvents(statusBar(),0);
    QCoreApplication::flush();
    QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
    }@

    However I observe that even though I do both sending and flushing not all status text setting are coming through, some are delayed. For example if there are 4 consecutive calls to my setStatusText and I am stopped in the debugger after all four but before returning to main event loop, then actually displayed text (on Mac OS X) shows only results of the 2nd call but not the 4th. This happens regardless on the order in which I invoke sendPostedEvents & flush.

    Any ideas how I can fix it?



  • How do you call setText()?
    Do you execute the long operation in a separate thread?



  • setStatusText() is being called from main execution thread, not from a separate thread.



  • Take a look at the last post.
    http://qt-project.org/forums/viewthread/43092/



  • I think complexities of asynchronous worker threads are not justified in my case and am looking for a simple solution. I don't need to have other aspects of GUI responsive. App window is already movable and I don't want user to be able to interact with GUI controls. I want to only refresh displayed text.

    By the way, doing flush() after processEvents() does not help either.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.