Results 1 to 7 of 7

Thread: Switching between 2 Forms

  1. #1
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Switching between 2 Forms

    Hey,

    I was looking at the following link:

    http://www.qtcentre.org/threads/2725...Forms-Handling

    I wasn't able to get the 2 forms switching with a button.

    sudhansu suggested:
    create a pointer to form2 in form1 class. allocate memory in constructor.
    inside button_on_click slot "call pointer->show();"

    I think I may have done this incorrectly, would someone be able to show an example of what I should have coded for that section sudhansu suggested?

    Thanks,
    Strateng

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Switching between 2 Forms

    What do you mean with form switching?
    Your post and the one you refer to don't explain this.

    Do you want to have a button on form 1 and when clicking on it show form 2?
    Do you also want to have a button on form 2 and when clicking on it show form 1?

  3. #3
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Switching between 2 Forms

    Thanks for the reply tbscope.

    Oh sorry I thought the one I was referring to actually explained it but I would like a button on form 1 when I click it to show form 2.

    At the moment I thought I could use the following code but it doesn't work
    Form2 f2;
    f2.show();

    Thanks,
    Strateng

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Switching between 2 Forms

    The following code is pseudo code (as it may contain syntax errors). It's just to give you an idea.
    It also assumes you have a form 1 with a button on it.

    Qt Code:
    1. Class Form1 : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Form1(QWidget *parent = 0);
    7.  
    8. private:
    9. Form2 *mySecondForm;
    10. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Form1::Form1(QWidget *parent) : Dialog(parent)
    2. {
    3. // standard ui setup here...
    4.  
    5. mySecondForm = new Form2(this);
    6.  
    7. connect(ui->buttonShowForm2, SIGNAL(clicked()), mySecondForm, SLOT(show()));
    8. }
    To copy to clipboard, switch view to plain text mode 

    Try something like that.

  5. #5
    Join Date
    Mar 2010
    Posts
    28
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Switching between 2 Forms

    Thanks for your reply but sadly I am still unable to get to the other form using similar sample coding you provided.

    Thanks,
    Strateng

    Quote Originally Posted by tbscope View Post
    The following code is pseudo code (as it may contain syntax errors). It's just to give you an idea.
    It also assumes you have a form 1 with a button on it.

    Qt Code:
    1. Class Form1 : public QDialog
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Form1(QWidget *parent = 0);
    7.  
    8. private:
    9. Form2 *mySecondForm;
    10. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Form1::Form1(QWidget *parent) : Dialog(parent)
    2. {
    3. // standard ui setup here...
    4.  
    5. mySecondForm = new Form2(this);
    6.  
    7. connect(ui->buttonShowForm2, SIGNAL(clicked()), mySecondForm, SLOT(show()));
    8. }
    To copy to clipboard, switch view to plain text mode 

    Try something like that.

  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: Switching between 2 Forms

    Thanks for your reply but sadly I am still unable to get to the other form using similar sample coding you provided.
    How about you put a little effort in to explaining exactly how you are trying to do it, what does and does not happen etc. Post a short example that demonstrates what you are doing and how that fails. We could spend a small eternity playing guessing games otherwise.

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

    Default Re: Switching between 2 Forms

    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.


Similar Threads

  1. Multiple Forms and vertical layout in forms
    By eva2002 in forum Qt Programming
    Replies: 0
    Last Post: 13th January 2010, 05:05
  2. Switching between two databases
    By codeman in forum Qt Programming
    Replies: 20
    Last Post: 13th May 2009, 14:33
  3. Switching 5.2 from 5.0.2
    By baray98 in forum Qwt
    Replies: 1
    Last Post: 11th May 2009, 17:59
  4. Layouting "Windows.Forms" like Qt forms
    By Boron in forum Qt Tools
    Replies: 1
    Last Post: 29th April 2008, 22:01
  5. switching between pages
    By Kapil in forum Newbie
    Replies: 9
    Last Post: 6th March 2006, 10:57

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.