Results 1 to 4 of 4

Thread: MessageBox comes before MainWindow

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Symbian S60

    Default Re: MessageBox comes before MainWindow

    Thanks for the reply,

    I made it public slot and also changed its name to "doConnectDatabase"
    and then, I typed
    Qt Code:
    1. emit doConnectDatabase()
    To copy to clipboard, switch view to plain text mode 
    instead of
    Qt Code:
    1. connectDatabase()
    To copy to clipboard, switch view to plain text mode 

    but nothing changed, any other ideas?

  2. #2
    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: MessageBox comes before MainWindow

    Your main window doesn't show because it is not even constructed at the time you fail to open the database. Your attempt to close the un-constructed window may schedule a close event but it will almost certainly be followed nearly immediately with the show event scheduled in your main().

    You need to schedule the attempt to open the database for a point in time after the main window is constructed and visible. You can do this with a zero length, single shot timer. Convert you existing connectDatabase() to a slot and make your constructor look like this:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. QTimer::singleShot(0, this, SLOT(connectDatabase()));
    8. }
    To copy to clipboard, switch view to plain text mode 

    The window will finish construction, return to the main event loop and be shown before the timer fires. When the timer event is processed the connection error should function as you expect.

Similar Threads

  1. Extending MessageBox
    By thru in forum Qt Programming
    Replies: 7
    Last Post: 17th December 2010, 16:31
  2. MessageBox appearnig twice.
    By ronak.vashi in forum Newbie
    Replies: 7
    Last Post: 30th November 2010, 07:45
  3. show messagebox
    By chinmayapadhi in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2010, 13:35
  4. MessageBox Validation
    By fortyhideout12 in forum Newbie
    Replies: 10
    Last Post: 2nd September 2009, 17:14
  5. QSA 1.2.1 && MessageBox
    By xk in forum Newbie
    Replies: 0
    Last Post: 20th April 2006, 17:30

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
  •  
Qt is a trademark of The Qt Company.