Creating wait screen



  • Hello group,

    I was trying to create a screen(widget) which would display some wait symbol, while there is some background work is going on.
    Can i display a new widget on a different(new) thread? I don't have much idea about multithread programming. So if you guys can suggest me some resources, it will be very helpful to me :)

    Thanks & Regards,
    Durgesh K


  • Moderators

    Of course you can push the widget into a new thread. But be mindful about it - you'll need a new class (namely, QThread subclass), and there is the thing of communicating with main thread (your app), which again involves some writing. If you want to go for it, then you might want to prevent your widget from accepting events (it won't need them anyway), which may speed things up a bit in some situations.

    IMO, better solution is to leave the widget in main thread, as it won't do much work anyway.


  • Moderators

    You can't display a widget in a separate thread. All GUI elements have to run in the main thread. Your best bet would be to move your processing to a separate thread.

    There's a nice "wiki page":http://developer.qt.nokia.com/wiki/Threads_Events_QObjects about threading available too.


  • Moderators

    [quote author="mlong" date="1312577075"]You can't display a widget in a separate thread. All GUI elements have to run in the main thread. Your best bet would be to move your processing to a separate thread.

    There's a nice "wiki page":http://developer.qt.nokia.com/wiki/Threads_Events_QObjects about threading available too.
    [/quote]

    Ah, didn't know that, thanks, mlong!



  • Also, note that you can use "QProgressDialog":http://doc.qt.nokia.com/4.7/qprogressdialog.html to provide feedback on the progress of a slow operation.



  • Thanks guys for the answers, atleast now i know what not to try.

    @sigrid, if i use QProgressDialog then i will have to use qApp->processEvents(), in order to update the QProgressDialog, and since at the background i am running third party DLL, i can't update QProgressDialog properly.



  • You can always try to use "QProgressBar":http://doc.qt.nokia.com/latest/qprogressbar.html, set its minimum and maximum to 0 and its value to -1. And you get busy indicator without any progress only indicating that something is loading.


  • Moderators

    Unfortunately, a QProgressBar would suffer from the same shortcomings as a QProgressDialog if the main event loop is blocked by the work in progress. DurgeshK mentioned that his processing is running 3rd-party code, so there's no way to process events during the work being done.


Log in to reply
 

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