Results 1 to 4 of 4

Thread: doing a thing after the form is displayed

  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    692
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default doing a thing after the form is displayed

    Good morning this is what I would implement:
    just after that the main form is created and displayed I would connect to a database.
    I tried to add the code to connect to the database in the ctor of the main application but it connect before the main form is displayed. How can I avoid this behavior?
    Regards
    Franco Amato

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: doing a thing after the form is displayed

    Put the connection statements in an extra function and call it, after the main form was created/shown.

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

    franco.amato (25th January 2011)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: doing a thing after the form is displayed

    QMetaObject::invokeMethod(..., Qt::QueuedConnection) is also a good solution. It will run a slot only after starting the event loop.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #4
    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: doing a thing after the form is displayed

    Or you can use a zero duration single-shot timer at the end of the constructor to have a similar effect:
    Qt Code:
    1. MyClass::MyClass()
    2. {
    3. // stuff
    4. QTimer::singleShot(0, this, SLOT(doConnect()));
    5. }
    6.  
    7. // slot:
    8. void doConnect()
    9. {
    10. // whatever
    11. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. KDChart. What do you thing about?
    By Nadia in forum Qt-based Software
    Replies: 1
    Last Post: 15th February 2011, 01:55
  2. Replies: 4
    Last Post: 17th October 2010, 15:39
  3. Very strange thing
    By Sheng in forum Qt Programming
    Replies: 4
    Last Post: 21st October 2008, 22:44
  4. Form not displayed in QT Designer 4
    By demorphica in forum Qt Tools
    Replies: 2
    Last Post: 15th July 2008, 00:34
  5. There is QTimeEdit another thing in Qt4
    By Krishnacins in forum Qt Programming
    Replies: 1
    Last Post: 26th May 2006, 16:06

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.