Results 1 to 13 of 13

Thread: How to open another form in Qt4?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default How to open another form in Qt4?

    Hello there! I am new to the forum, so just bear with me...

    I am trying to open another form by clicking a button on the first form. I tried...
    Qt Code:
    1. form1 w;
    2. w.show();
    To copy to clipboard, switch view to plain text mode 

    And it shows form2 then immediately closes form2.

    Qt Code:
    1. form1 w;
    2. w->show();
    To copy to clipboard, switch view to plain text mode 

    Gives compiler error: "form1.cpp:84: error: base operand of '->' has non-pointer type 'form2'"

    Qt Code:
    1. static Form2 *form2 = new Form2(this);
    2. form2->show();
    3. form2->activateWindow();
    4. form2->raise();
    To copy to clipboard, switch view to plain text mode 

    gives compiler error: "form1.h:21: error: ISO C++ forbids declaration of 'Form2' with no type."
    and error: "C:\Users\sapslaj\Desktop\chat-build-desktop\..\chat\mainlogin.h:21: error: expected ';' before '*' token"

    I have tried everything I know possible, and I cannot get it to stay open. Any help?

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

    Default Re: How to open another form in Qt4?

    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
    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: How to open another form in Qt4?

    Quote Originally Posted by sapslaj View Post
    I am trying to open another form by clicking a button on the first form. I tried...
    Qt Code:
    1. form1 w;
    2. w.show();
    To copy to clipboard, switch view to plain text mode 
    And it shows form2 then immediately closes form2.
    What is the lifetime of the stack-allocated w object in C++? This is basic C++, not a Qt question.
    Given that w.show() is non-blocking, why do you think the window might go away?

    Qt Code:
    1. form1 w;
    2. w->show();
    To copy to clipboard, switch view to plain text mode 

    Gives compiler error: "form1.cpp:84: error: base operand of '->' has non-pointer type 'form2'"
    What do you think the error message is telling you? This is basic C++, not a Qt question. You might find some clues in your next snippet.

    Qt Code:
    1. static Form2 *form2 = new Form2(this);
    2. form2->show();
    3. form2->activateWindow();
    4. form2->raise();
    To copy to clipboard, switch view to plain text mode 

    gives compiler error: "form1.h:21: error: ISO C++ forbids declaration of 'Form2' with no type."
    and error: "C:\Users\sapslaj\Desktop\chat-build-desktop\..\chat\mainlogin.h:21: error: expected ';' before '*' token"
    Where is the class Form2 declared? This is basic C++, not a Qt question.

    You may have noticed a theme in my questions. You have all the elements of the Qt side of this problem here and in the FAQ page wysota gave you but your C++ knowledge is letting you down.

  4. The following user says thank you to ChrisW67 for this useful post:

    megazig (2nd September 2011)

Similar Threads

  1. Replies: 3
    Last Post: 11th June 2012, 15:21
  2. Replies: 7
    Last Post: 8th October 2010, 13:07
  3. Open one Form (widget)
    By vinny gracindo in forum Newbie
    Replies: 1
    Last Post: 7th October 2009, 13:13
  4. Replies: 10
    Last Post: 6th July 2008, 09:46
  5. Replies: 3
    Last Post: 13th May 2007, 20:55

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.