Results 1 to 3 of 3

Thread: Load one form on button click

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2012
    Posts
    49
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    14
    Thanked 3 Times in 3 Posts

    Default Load one form on button click

    hi,

    I am new to QT . I am trying to display one form from other form and hide the first form.

    I have created a project that includes the following files

    form1.h,form2.h,form1.cpp,form2.cpp,main.cpp,form1 .ui,form2.ui
    i am adding the source code over here.

    form1.h:

    Qt Code:
    1. #ifndef FORM1_H
    2. #define FORM1_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class form1;
    8. }
    9.  
    10. class form1 : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit form1(QWidget *parent = 0);
    16. ~form1();
    17.  
    18. public slots:
    19. void ButtonClicked();
    20. private:
    21. Ui::form1 *ui;
    22. };
    23.  
    24. #endif // FORM1_H
    To copy to clipboard, switch view to plain text mode 


    form2.h:

    Qt Code:
    1. #ifndef FORM2_H
    2. #define FORM2_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. namespace Ui {
    7. class form2;
    8. }
    9.  
    10. class form2 : public QMainWindow
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. explicit form2(QWidget *parent = 0);
    16. ~form2();
    17. public slots:
    18. void ButtonClicked();
    19. private:
    20. Ui::form2 *ui;
    21. };
    22.  
    23. #endif // FORM2_H
    To copy to clipboard, switch view to plain text mode 

    form1.cpp:
    Qt Code:
    1. #include "form1.h"
    2. #include "ui_form1.h"
    3. #include "form2.h"
    4.  
    5. form1::form1(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::form1)
    8. {
    9. ui->setupUi(this);
    10. }
    11.  
    12. form1::~form1()
    13. {
    14. delete ui;
    15. }
    16.  
    17. void form1::ButtonClicked()
    18. {
    19. form2 f2;
    20. this->hide();
    21. f2.show();
    22. }
    To copy to clipboard, switch view to plain text mode 


    form2.cpp:

    Qt Code:
    1. #include "form2.h"
    2. #include "ui_form2.h"
    3. #include"form1.h"
    4.  
    5. form2::form2(QWidget *parent) :
    6. QMainWindow(parent),
    7. ui(new Ui::form2)
    8. {
    9. ui->setupUi(this);
    10. }
    11.  
    12. form2::~form2()
    13. {
    14. delete ui;
    15. }
    16.  
    17. void form2::ButtonClicked()
    18. {
    19. form1 f1;
    20. this->hide();
    21. f1.show();
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 
    main.cpp:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "form1.h"
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. form1 w;
    8. w.show();
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    While doing thisthe form1 is getting hide and form 2 is not displaying.

    Could you please tell me what am missing..

    Thanks in Advance

    Regards
    vinith
    Last edited by wysota; 16th April 2012 at 16:53. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Load one form on button click

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2012
    Posts
    49
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    14
    Thanked 3 Times in 3 Posts

    Default Re: Load one form on button click

    t worked for me.

    Thanks

Similar Threads

  1. Replies: 3
    Last Post: 23rd February 2011, 12:03
  2. How can I know which button click.
    By electronicboy in forum Qt Programming
    Replies: 10
    Last Post: 4th October 2009, 14:27
  3. Help me to load one form over another form PushButton
    By wagmare in forum Qt Programming
    Replies: 7
    Last Post: 26th November 2008, 16:11
  4. Load form mdi child plugin
    By estanisgeyer in forum Qt Programming
    Replies: 4
    Last Post: 10th February 2008, 14:27
  5. Replies: 4
    Last Post: 31st August 2006, 12:11

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.