Results 1 to 3 of 3

Thread: execute function after widget is displayed.

  1. #1
    Join Date
    Nov 2010
    Location
    Poland, Poznań
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default execute function after widget is displayed.

    Hello.

    I have a litle problem.
    For testing purposes imagine a simple app witch a single button.
    Clicking this button creates new window (basic QDialog), that contains fiew QLineEdits and QLabel's.

    Code for that window also contains a time - consuming function.

    Problem is: i would like to deley execution of this function till mentioned window is fully drawn.

    Currently function is exeuted before window appears, so - more time this function needs - more time it takes to show my window.

    My target is, as i have mentioned:
    Application starts -> user clicks on the button -> new (children) window appears -> function included in this winow code is executed.

    Thanks in advance for any help

    PS:
    I hope my English is readable enough.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: execute function after widget is displayed.

    You can use a 0 millisecond single shot timer started from the constructor of the dialog to call the function (as a slot) after the program returns to the event loop.
    Qt Code:
    1. MyDialog()
    2. {
    3. ...
    4. QTimer::singleShot(0, this, SLOT(doLongRunningThings()));
    5. }
    6.  
    7. /* public or private slot */
    8. void doLongRunningThings()
    9. {
    10. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to ChrisW67 for this useful post:

    quain (6th December 2010)

  4. #3
    Join Date
    Nov 2010
    Location
    Poland, Poznań
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: execute function after widget is displayed.

    Thank you very much

    You idea work's perfect in my case.

Similar Threads

  1. Replies: 1
    Last Post: 1st December 2010, 23:16
  2. EXC_BAD_ACCESS error when widget is displayed
    By sparticus_37 in forum Qt Programming
    Replies: 0
    Last Post: 19th August 2010, 06:55
  3. Replies: 2
    Last Post: 30th July 2010, 15:59
  4. Dynamic widget not displayed upon Qwidget
    By ashukla in forum Qt Programming
    Replies: 5
    Last Post: 17th December 2007, 11:11
  5. Replies: 1
    Last Post: 20th November 2007, 18:42

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.