Results 1 to 4 of 4

Thread: Show Widget B if an event in Widget A occurred ?

  1. #1
    Join Date
    Jul 2011
    Posts
    16
    Thanks
    8
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Show Widget B if an event in Widget A occurred ?

    Hello Folks,

    I have Widgets A and B. Lets say Widget A has a push button to assign x1=true, while it is initially is initialized to false.

    What i want to do is show Widget A, then after pressing the push button Widget A hides and Widget B appears.

    I 'think' I am not really understanding the loop event sequence. My code is as the following:


    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3. #include "startupscreen.h"
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7.  
    8. StartUpScreen startup;
    9. startup.show();
    10.  
    11. if (startup.x1)
    12. {
    13. MainWindow w;
    14. w.show();
    15. startup.hide();
    16. }
    17. return a.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    Thank you very much,

  2. #2
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Show Widget B if an event in Widget A occurred ?

    Why you don't open the MainWindow inside the pushbutton event?
    Something like:
    Qt Code:
    1. MainWindow * w = new MainWindow(0); // in the constructor, paarent should be zero, so we can delete StartUpScreen without problems.
    2. w->show();
    3. deleteLater();
    To copy to clipboard, switch view to plain text mode 

    Hth.

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Show Widget B if an event in Widget A occurred ?

    w goes out of scope, so you don't have a chance to see it.
    ---
    sorry, actually I paid more attention to the code rather than your question
    You should wait and react on the push button click, because this
    Qt Code:
    1. startup.show();
    2.  
    3. if (startup.x1)
    4. ...
    To copy to clipboard, switch view to plain text mode 
    does not give the main event loop a chance to start before you check the variable.
    Instead of assigning a variable, create and show the second window.
    Last edited by stampede; 2nd August 2011 at 22:16.

  4. #4
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Show Widget B if an event in Widget A occurred ?

    I don't think so...

    StartUpScreen will appear just when we enter the "a.exec()", which is after the validation of x1....

Similar Threads

  1. tree widget item's widget don't respond to any event.
    By quantity in forum Qt Programming
    Replies: 0
    Last Post: 11th April 2011, 05:30
  2. How to not show widget
    By gQt in forum Qt Programming
    Replies: 9
    Last Post: 10th June 2010, 20:59
  3. Replies: 10
    Last Post: 29th May 2010, 19:42
  4. Replies: 7
    Last Post: 14th January 2010, 09:47
  5. How to show the widget?
    By kommu in forum Qt Programming
    Replies: 1
    Last Post: 21st October 2008, 09:43

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.