Results 1 to 4 of 4

Thread: QMainWindow: create onStartup-like function [SOLVED]

  1. #1
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QMainWindow: create onStartup-like function [SOLVED]

    My application has a QMainWindow and I need to run one of its functions after the QApplicaiton event engine is running. Any suggestions?

    Qt Code:
    1. #include <QApplication>
    2. #include "mainwindow.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication app(argc, argv);
    7. MainWindow mainWin;
    8. mainWin.show();
    9. return app.exec(); //Right after this, event engine is running. How to send something to my mainWin to run my onStarup()? signal? event??
    10. }
    11.  
    12. //MainWin...
    13. MainWindow::MainWindow() {}
    14. MainWindow::onStartup() {} //Call this, display a QProgressBar and do some stuff
    To copy to clipboard, switch view to plain text mode 
    Last edited by thomaspu; 11th October 2012 at 14:43.

  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: QMainWindow: create onStartup-like function

    Use QMetaObject::invokeMethod() with Qt::QueuedConnection.
    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.


  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMainWindow: create onStartup-like function

    In MainWindow declare onStartup as a slot and in constructor use something like this :
    Qt Code:
    1. QTimer::singleShot(0,this,SLOT(onStartup());
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Nov 2006
    Posts
    86
    Thanks
    6
    Thanked 14 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMainWindow: create onStartup-like function

    Cool, thats just what I was looking for.

    Paul

Similar Threads

  1. Create QMainWindow in runtime
    By qt_developer in forum Newbie
    Replies: 2
    Last Post: 25th June 2012, 19:22
  2. Problem with using raise function on QMainWindow
    By yartov in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2008, 09:14
  3. how to create a new function
    By tommy in forum Qt Programming
    Replies: 3
    Last Post: 10th November 2007, 17:08
  4. Modal dialog in QMainWindow's event() function
    By tanminh in forum Qt Programming
    Replies: 1
    Last Post: 22nd June 2007, 09:46
  5. run function before closing QMainWindow
    By raphaelf in forum Newbie
    Replies: 1
    Last Post: 31st August 2006, 09:21

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.