Results 1 to 4 of 4

Thread: Showing a dialog at application startup

  1. #1
    Join Date
    Mar 2007
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Showing a dialog at application startup

    For my program, I need to pop up a dialog at first run so that the user can enter the directory where the data files are (they don't come with the program). I can look at my configuration file to decide whether or not to show the dialog - the question is where in my code to show it. If I put it in main() before app.exec(), the even loop won't have started yet, so it won't be responsive. I suspect there's an even handler in my main window class that I need to implement, but I can't figure out which one from the documentation.

    The code path I think I need:
    *Create main window
    * run app.exec
    * some even handler gets called
    * show dialog

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Showing a dialog at application startup

    In my opinion make ur own window class...
    from main call the mainwindow. In the window class, keep a function to get input from the user as u expect. from the mainwindow constructor, call the function using QTimer::singleShot() .

    This will display ur main window and also pop up the input dialog. After the input u can call some function to initialize ur data. This approach will help in case u later dont want to call the input dialog . You can still show the window without it.


    Pseudo code :

    Qt Code:
    1. main()
    2. {
    3. ...
    4. MainWindow window;
    5. window.show();
    6. return app.exec();
    7. }
    8.  
    9.  
    10. // mainwindow
    11. class MainWindow:public QMainWindow
    12. {
    13. MainWindow()
    14. {
    15. ...
    16. QTimer::singleshot(getInput(),0); // call the input function using timer
    17. }
    18.  
    19. };
    20.  
    21. void MainWindow::getInput()
    22. {
    23. // pop dialog
    24. // initialize variables
    25. }
    To copy to clipboard, switch view to plain text mode 

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

    PaladinOfKaos (1st April 2008)

  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: Showing a dialog at application startup

    A modal dialog spins its own event loop so you can put it in main().

  5. #4
    Join Date
    Mar 2007
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Showing a dialog at application startup

    The QTimer::singleShot method looks like it will do what I need. Thanks!

Similar Threads

  1. QSkinWindows Classes
    By kernel_panic in forum Qt-based Software
    Replies: 45
    Last Post: 20th April 2010, 12:35
  2. Application Lockup poping up dialog
    By Tommytrojan in forum Qt Programming
    Replies: 6
    Last Post: 30th July 2007, 20:44
  3. Replies: 3
    Last Post: 31st March 2006, 18:38
  4. Replies: 1
    Last Post: 15th February 2006, 22:17

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.