Results 1 to 8 of 8

Thread: My showevent does not work properly.

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default My showevent does not work properly.

    void Ui_main::showEvent(QShowEvent * event )
    {
    qDebug()<<event->type();
    }
    I only see the value 17 before the window be displayed.
    I want to catch it just AFTER the window is displayed.
    Have I to use another event handling?

    And, is there an event (for example) 'ready' to be sure that my window is ready for first time ? (So, I can avoid to control the showevent trigger when a window minimized is maxified)

    Any help ? Thanks

  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: My showevent does not work properly.

    Please put your code snippets in [code] tags.

    It's hardly surprising that you receive a QEvent of type QEvent::Show in the handler for events of that type.

    For my money, the window is "ready" after you construct it and visible after you show() it. Another definition of "ready" might mean "returned to the event loop after the show()". Look at using a zero duration single-shot timer from the window constructor to trigger a slot immediately after the event loop is reached.

    If you read the QShowEvent docs you will see there are two types of event: spontaneous and not. User triggered events will be spontaneous, the programmatic show() of the window is not (at least on my machine).

  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: My showevent does not work properly.

    Excuse me for the code tags missing.
    I understand the QT events, but believe me I dont know how to be sure that the window is already showed.
    I want to show the main window and before doing more things I want to check some issues.
    If something is wrong I want to show a messagebox showing the information to the user and close the window.
    Now, because the event is launched before the main window is show, my user would see first a messagebox .
    How can I to fix the problem.?
    Thanks

  4. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: My showevent does not work properly.

    Try this:
    Qt Code:
    1. void MyMainWindow::showEvent(QShowEvent *e)
    2. {
    3. QTimer::singleShot(20, this, SLOT(showSomeDialogUponSomeAction()));
    4. }
    5.  
    6. void MyMainWindow::showSomeDialogUponSomeAction()
    7. {
    8. ...
    9. }
    To copy to clipboard, switch view to plain text mode 
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: My showevent does not work properly.

    It works!
    So, the trick is to wait some seconds or calling the slot ?
    (The 'slot call' means a whole process or pending events?)

    And, also can be a solution to process all events instead of using the singleshot?
    I have try "QCoreApplication:rocessEvents" but it does not work
    (I see the messagebox before the window)

    Thank you very much.
    Last edited by tonnot; 17th February 2011 at 09:23.

  6. #6
    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: My showevent does not work properly.

    Or this, as mentioned in my response:
    Qt Code:
    1. void MyMainWindow::MyMainWindow(...)
    2. {
    3. ...
    4. QTimer::singleShot(0, this, SLOT(showSomeStuffLater()));
    5. }
    6.  
    7. void MyMainWindow::showSomeStuffLater()
    8. {
    9. ...
    10. }
    11.  
    12. // then
    13.  
    14. ...
    15. MyMainWindow *w = new MyMainWindow(...);
    16. w->show();
    17. ...
    To copy to clipboard, switch view to plain text mode 
    The slot will be called as soon as the program returns to the event loop after executing show() (and whatever follows it).

  7. #7
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: My showevent does not work properly.

    Yes... it can be another solution.
    But it implies to have a Qtimer and a slot.
    I remember 'doEvents' from old VB, Is there somehing like in QT ?
    Thank you

  8. #8
    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: My showevent does not work properly.

    Yes, you've already tried it and declared it does not solve your problem.

    Why are you still looking for a solution?

Similar Threads

  1. Replies: 8
    Last Post: 19th August 2010, 13:18
  2. QGraphicsView::scale does not work properly.
    By metdos in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2010, 09:58
  3. QT's style sheet does not work properly on Mac OS X
    By sanjayshelke in forum Qt Programming
    Replies: 1
    Last Post: 10th December 2009, 11:50
  4. QLineF::intersect does not work properly (solved)
    By jano_alex_es in forum Newbie
    Replies: 1
    Last Post: 23rd June 2009, 10:06
  5. Why can't I make dynamic_cast work properly?
    By pir in forum General Programming
    Replies: 13
    Last Post: 18th July 2006, 17: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.