Results 1 to 6 of 6

Thread: qApp->processEvents() question QWidget/QDialog

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qApp->processEvents() question QWidget/QDialog

    I am sorry, but it is really, really hard to understand your post...
    One thing: you're calling processEvents in unneeded places. Your dialog is not modal( you show it with show(), not exec() ).

    Also, in SettoClose, just make selfclose = true and let it close itself in Increment ( because selfclose will be true ). And what is with those constants( 469, etc )?

    And if status > stop, then you start again. Is this what you want?

    Perhaps you can explain better what you are trying to achieve.
    While the preload is active, do you want to be able to interact with it's parent window?
    Last edited by marcel; 17th May 2007 at 18:04.

  2. #2
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: qApp->processEvents() question QWidget/QDialog

    Quote Originally Posted by marcel View Post
    I
    Perhaps you can explain better what you are trying to achieve.
    While the preload is active, do you want to be able to interact with it's parent window?

    i try to have a mix from QSplashScreen && QProgressDialog && a benchmark to stop time
    how long mysql is connect on remote host....

    if i set the image on a QWidget progress not run if a QDialog progress run && all other process stop .... I solved now and i emit progress from a QThread ...
    is not clean but run.... so all other function can continue to run ....

    and red line continue progress just as mysql is connect...


    Qt Code:
    1. void ProduceWait::run()
    2. {
    3. setTerminationEnabled(true);
    4. qDebug() << "### QThread run start ------------------------------- ";
    5. if (sconnect) {
    6. while( subsection ) {
    7. sai++;
    8. msleep (10);
    9. //////////////waiter->Increment();
    10. qDebug() << "### QThread running prim ..." << sai << " text." << text;
    11. emit TimeStatusQui(); /* progess continue */
    12.  
    13. if (!sconnect && sai < 100) {
    14. /* display minimal time progress ... 3.5 sec*/
    15. bool incanna = true;
    16. int lastsai = sai;
    17. while( subsection ) {
    18. sai++;
    19. qDebug() << "### QThread running slave ..." << sai << " text." << text;
    20. msleep (10);
    21. emit TimeStatusQui(); /* progess continue */
    22.  
    23. if (sai > 350) {
    24. qDebug() << "### QThread stop a ................................";
    25. emit statusMessage(tr("Total %1 msec. to %2.").arg(lastsai * 10).arg(text));
    26. terminate();
    27. wait(10);
    28. incanna = false;
    29. return;
    30. }
    31.  
    32. }
    33. } else if (!sconnect) {
    34. qDebug() << "### QThread stop b ................................";
    35. emit statusMessage(tr("Total %1 msec. to %2.").arg(sai * 10).arg(text));
    36. terminate();
    37. wait(10);
    38. return;
    39. } else if (sai > 10000) {
    40. qDebug() << "### QThread stop c ................................";
    41. emit statusMessage(tr("Time out to %2.").arg(text));
    42. terminate();
    43. wait(10);
    44. return;
    45. }
    46. }
    47.  
    48. } else {
    49. qDebug() << "### QThread stop ................................";
    50. terminate();
    51. wait(10);
    52. }
    53. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qApp->processEvents() question QWidget/QDialog

    For QWidget try setWindowFlags( Qt::Widget | Qt::WindowStaysOnTopHint ).

    By the way, whay aren't you using a QSplashScreen? You have the drawContents function in which you can custom draw and make it look just as the dialog is looking now.

  4. #4
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: qApp->processEvents() question QWidget/QDialog

    Quote Originally Posted by marcel View Post
    For QWidget try setWindowFlags( Qt::Widget | Qt::WindowStaysOnTopHint ).

    By the way, whay aren't you using a QSplashScreen? You have the drawContents function in which you can custom draw and make it look just as the dialog is looking now.

    O ye.. i say that is possibel to draw on QSplashScreen ... to display progress bar inside QSplashScreen and signal and minimal time to stay open .....
    To make all this or subclass QSplashScreen is easy make a QWidget from zero...

    The problem on QSplashScreen is the minimal time to display ... whitout a QThread...

    on main.cpp void i start :

    Qt Code:
    1. Gui_Main *w = new Gui_Main();
    2. w->setWindowTitle( _PROGRAM_TITLE_ );
    3. w->hide();
    To copy to clipboard, switch view to plain text mode 

    if mysql is connect or timeout Gui_Main is show.. the effect is same as QSplashScreen and i can display on minimal time x..

    many roads go to Rome ... and now i am happy to write my first QThread

    I can only not understand how handle a QThread whit exec inside run().. like a sqlquery


    Qt Code:
    1. void Gui_Main::WaitConnectEnd( QString txt )
    2. {
    3. quiwaiter->hide();
    4. quiwaiter->close();
    5. quiwaiter->deleteLater();
    6. show();
    7. Status_MSG(txt);
    8. cannino = 0; /* reset time */
    9. }
    10.  
    11. void Gui_Main::AIncrement()
    12. {
    13. cannino++; /* each 10 msec... one */
    14. QString st = tr("Master Connection on host %1 - check %2").arg(OneVar["dbhost1"]).arg(cannino);
    15. quiwaiter->Increment();
    16. quiwaiter->SetText( st );
    17. quiwaiter->setFocus ( Qt::MouseFocusReason );
    18. hide();
    19. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qApp->processEvents() question QWidget/QDialog

    exec() starts the thread's event loop.

    You need an event loop in a thread only if:
    - you connect signals from other threads to slots in your thread - this is because of queued connection - the signals emitted from other threads will actually be posted as events in your thread's event loop.
    - you use a QTimer - because it will post events in the thread that created it.
    - you use custom events and post them in your thread.

    If you don't do any of these then I suggest dropping the exec().

    ALSO, about using terminate inside run():
    Warning: This function is dangerous and its use is discouraged. The thread can be terminate at any point in its code path. Threads can be terminated while modifying data. There is no chance for the thread to cleanup after itself, unlock any held mutexes, etc. In short, use this function only if absolutely necessary. Termination can be explicitly enabled or disabled by calling QThread::setTerminationEnabled(). Calling this function while termination is disabled results in the termination being deferred, until termination is re-enabled. See the documentation of QThread::setTerminationEnabled() for more information.
    Therefore I suggest using a flag ( for example mFinished - volatile bool ), that you test in your loop conditions. Instead of calling terminate you can set mFinished to true, and the thread will exit on its own, when it first encounters the condition.

    And you may wanna make good use of the QThreaf::finished signal. This is emitted when a thread is finished - so then you are absolutely sure that the thread exited run().

    Regards

  6. The following user says thank you to marcel for this useful post:

    patrik08 (17th May 2007)

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
  •  
Qt is a trademark of The Qt Company.