Results 1 to 8 of 8

Thread: Newbie with an instant question on how to open a second form..

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

    Default Newbie with an instant question on how to open a second form..

    Hi,

    Microbrain here, trying to move to QT from visual basic since I am told I can make apps for windows and linux all in the same language.
    but what a struggle! - Anyway I need to know if there is a simple command to open a second (different) form from the first one.

    thnx.

  2. #2
    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: Newbie with an instant question on how to open a second form..

    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
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Newbie with an instant question on how to open a second form..

    What kind of form? A dialog? Some other QWidget derived object?

    Try exec() or show()

  4. #4
    Join Date
    Apr 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Newbie with an instant question on how to open a second form..

    OK,

    I managed to sort that one out eventually, but can anybody tell me whether it's possible to write c programs on qt4 ? c++ is nothing more than an unneccessary layer of crap added to what was once a pretty good language, it serves no purpose whatsoevver other than to totally confuse.

  5. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Newbie with an instant question on how to open a second form..

    Qt in C would be a nightmare to code for and be totally confusing for both the people attempting to maintain it and the people trying to use it as a framework. Not to mention that the amount of code duplication needed would be hideous.

  6. #6
    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: Newbie with an instant question on how to open a second form..

    Qt in C would be WinAPI--
    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.


  7. #7
    Join Date
    Oct 2010
    Posts
    6
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Newbie with an instant question on how to open a second form..

    please give me a full example for this problem iam a newbie in QT and C++ and i don't understand it :-S
    Qt Code:
    1. #include <QApplication>
    2. #include <QFont>
    3. #include <QPushButton>
    4. #include <QWidget>
    5. #include "form2.h"
    6.  
    7. class MyWidget : public QWidget
    8. {
    9. public:
    10. MyWidget(QWidget *parent = 0);
    11. virtual ~MyWidget();
    12. virtual void openForm2();
    13. };
    14.  
    15. MyWidget::MyWidget(QWidget *parent)
    16. : QWidget(parent)
    17. {
    18. setFixedSize(200, 120);
    19.  
    20. QPushButton *quit = new QPushButton(tr("Quit"), this);
    21. quit->setGeometry(62, 40, 75, 30);
    22. quit->setFont(QFont("Times", 18, QFont::Bold));
    23.  
    24. connect(quit, SIGNAL(clicked()), qApp, SLOT(openForm2()));
    25. }
    26.  
    27. int main(int argc, char *argv[])
    28. {
    29. QApplication app(argc, argv);
    30. MyWidget widget;
    31. widget.show();
    32. return app.exec();
    33. }
    34.  
    35. void MyWidget::openForm2(){
    36.  
    37. static MyWidget *form2 = new MyWidget(this);
    38. form2->show();
    39. form2->activateWindow(); // or form2->setActiveWindow() in Qt3
    40. form2->raise();
    41. }
    To copy to clipboard, switch view to plain text mode 
    i had 2 form in this : form1.ui and form2.ui
    i use QT4

    Thanks

  8. #8
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Newbie with an instant question on how to open a second form..

    Hi,

    Please see the thread More than one forms. One of the replies has an attachment with an example project.

    If you don't know C++ when you start to use Qt, you won't get very far. Get yourself a good book. C++ is not just some crap ontop C. It brings object oriented programming into C. Object oriented programming is one of the fundamental characteristics of many programming languagues today, even of many scripting languages.

    Regards,
    Marc

  9. The following user says thank you to marcvanriet for this useful post:

    takechi (9th October 2010)

Similar Threads

  1. No instant response in while(1) loop?
    By casual0402 in forum Qt Programming
    Replies: 2
    Last Post: 20th March 2010, 16:09
  2. Open one Form (widget)
    By vinny gracindo in forum Newbie
    Replies: 1
    Last Post: 7th October 2009, 13:13
  3. Newbie Designer question
    By JariV in forum Qt Tools
    Replies: 0
    Last Post: 15th February 2009, 22:24
  4. Replies: 3
    Last Post: 13th May 2007, 20:55
  5. Newbie threading question
    By deepayan in forum Qt Programming
    Replies: 17
    Last Post: 16th April 2007, 00:25

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.