Results 1 to 3 of 3

Thread: Can I force my MainWindow to initialize its widgets before calling app.exec() ?

  1. #1
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Can I force my MainWindow to initialize its widgets before calling app.exec() ?

    In my project, I use alot of direct non-Qt OpenGL calls.

    At some point during startup I want an opportunity to create/load some initial OpenGL resources. To do this, I need to call QOpenGLWidget::makeCurrent(),

    My problem is, I can't call "QOpenGLWidget::makeCurrent()" until after application.exec() is entered. Is there some way I can force my QMainWindow's child QOpenGLWidgets to be initialized before application.exec() is entered?

    =
    Qt Code:
    1. MainWindow mainWindow(argc, argv);
    2. if(!mainWindow.Initialize()) //I'd really like to load my OpenGL resources here...
    3. {
    4. return EXIT_FAILURE;
    5. }
    6.  
    7. return application.exec(); //But QOpenGLWidget hasn't created the OpenGL context until this is entered.
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Can I force my MainWindow to initialize its widgets before calling app.exec() ?

    You can do some event processing by either calling QApplication::processEvents() or by using a local QEventLoop.

    But delay something until the event loop runs, you can also call a slot via single shot timer or QMetaObject::invokeMethod().
    Another technique is to do something the first time the main window's showEvent() is being called.

    Cheers,
    _

  3. #3
    Join Date
    Apr 2009
    Location
    www.JaminGrey.com
    Posts
    71
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Can I force my MainWindow to initialize its widgets before calling app.exec() ?

    Thank you! What I ended up doing is call qApp->processEvents() in mainWindow.Initialize(), like you suggest, and use a bool to test and return early in the overridden QOpenGLWidget:aintGL() function for any paint events that are triggered before mainWindow.Initialize() has actually finished.

    I appreciate you taking the time to answer!

Similar Threads

  1. QDrag::exec is not calling QGraphicsView mouseRelease
    By wagmare in forum Qt Programming
    Replies: 0
    Last Post: 25th March 2015, 09:33
  2. Force all widgets in a QGridLayout to be visible
    By SeanM in forum Qt Programming
    Replies: 2
    Last Post: 29th January 2014, 22:07
  3. how to force widgets update
    By Onanymous in forum Newbie
    Replies: 5
    Last Post: 14th June 2010, 17:37
  4. Calling QThread::exec() repeatedly
    By hb in forum Qt Programming
    Replies: 2
    Last Post: 26th June 2007, 20:24
  5. initialize child widgets within parent?
    By ucomesdag in forum Newbie
    Replies: 6
    Last Post: 6th June 2006, 08:11

Tags for this Thread

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.