Results 1 to 14 of 14

Thread: Problem with connect?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2013
    Location
    England
    Posts
    13
    Thanks
    7
    Qt products
    Qt5
    Platforms
    Windows

    Unhappy Problem with connect?

    Hey,

    I am currently creating a program and have encountered a small problem.

    I have a QWidget (MainMenu) with a pushbutton on and a slot called void MainMenu::button1Clicked();
    On the click of this button, it closes MainMenu and opens up my second widget (PageTwo).

    This works fine, however on PageTwo, the pushbutton to return to MainMenu does not work, it simply closes the widget as it is supposed to, but doesnt run MainMenu



    Mainmenu class: (button works fine!)
    Qt Code:
    1. MainMenu::MainMenu(QWidget *parent)
    2. : QWidget(parent)
    3.  
    4. {
    5.  
    6. QWidget *MainMenu1 = new QWidget;
    7.  
    8. QPushButton *button1 = new QPushButton;
    9. connect(button1, SIGNAL(clicked()),MainMenu1, SLOT(close()));
    10. connect(button1,SIGNAL(clicked()),this,SLOT(button1Clicked()));
    11.  
    12. MainMenu -> show();
    13.  
    14. }
    15.  
    16.  
    17.  
    18. void MainMenu::button1Clicked()
    19. {
    20. Page2 w;
    21.  
    22. }
    To copy to clipboard, switch view to plain text mode 

    My second class , it opens up fine but will not run MainMenu when the button is clicked as it does the first time
    Qt Code:
    1. Page2::Page2(QWidget *parent)
    2. : QWidget(parent)
    3. {
    4.  
    5.  
    6. QWidget *PageTwo = new QWidget;
    7.  
    8. QPushButton *button2 = new QPushButton;
    9. connect(button2, SIGNAL(clicked()),PageTwo, SLOT(close()));
    10. connect(button2,SIGNAL(clicked()),this,SLOT(button2Clicked()));
    11.  
    12. PageTwo -> show();
    13.  
    14. }
    15.  
    16.  
    17.  
    18. void Page2::button2Clicked()
    19. {
    20. MainMenu w;
    21.  
    22. }
    To copy to clipboard, switch view to plain text mode 



    Thanks in advance for any replies.. It is really confusing me as to why the first button works perfectly fine but the second one will not even though the code is practically the same...
    P.S i am not recieving any errors, main menu is just not showing!
    Last edited by Jake123; 22nd January 2013 at 16:17.

Similar Threads

  1. Problem with connect
    By Momergil in forum Newbie
    Replies: 8
    Last Post: 29th July 2011, 01:27
  2. Problem with connect
    By eekhoorn12 in forum Newbie
    Replies: 3
    Last Post: 21st December 2010, 20:48
  3. connect() problem
    By harmodrew in forum Newbie
    Replies: 14
    Last Post: 5th August 2010, 17:45
  4. connect problem
    By liengen in forum Newbie
    Replies: 2
    Last Post: 22nd October 2008, 16:21
  5. Problem with connect()
    By mrnor3 in forum Qt Programming
    Replies: 3
    Last Post: 23rd July 2008, 14:05

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.