Results 1 to 3 of 3

Thread: Initialization code

  1. #1
    Join Date
    Jan 2006
    Location
    Berkeley California
    Posts
    109
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Initialization code

    How can I get an initialization function to run once "return( app.exec )" is run?

    Thanks

  2. #2
    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: Initialization code

    Either use a QTimer with a 0 timeout or run it before app.exec()

  3. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Initialization code

    Quote Originally Posted by Doug Broadwell View Post
    How can I get an initialization function to run once "return( app.exec )" is run?
    This does not make much sense... But I guess you probably meant once app.exec() is run and before it returns otherwise it wouldn't be an initialization function and would be as simple as that :
    Qt Code:
    1. int retcode = app.exec();
    2. someCleanupFunction();
    To copy to clipboard, switch view to plain text mode 

    However if you need initializations to be done the function as to be called after the QApplication object is created (or instanciations of painting related classes will fail) and, depending of whether they need an running event loop or not...
    Qt Code:
    1. staticInitFunction();
    2.  
    3. SomeDynamicInitObject dynamicInitObject;
    4.  
    5. QTimer::singleShot(0, &dynamicInitObject, SLOT( dynamicInitFunction() );
    6.  
    7. return app.exec();
    To copy to clipboard, switch view to plain text mode 
    Last edited by fullmetalcoder; 27th February 2007 at 11:49. Reason: fixed a typo in code
    Current Qt projects : QCodeEdit, RotiDeCode

Similar Threads

  1. Pasting code from code tag in emacs
    By Gopala Krishna in forum General Discussion
    Replies: 0
    Last Post: 16th February 2007, 05:47
  2. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  3. Problem closing a QMainWindow in Qt4.2
    By ian in forum Qt Programming
    Replies: 11
    Last Post: 17th October 2006, 00:49
  4. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 21:41

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.