Results 1 to 17 of 17

Thread: More than one forms

  1. #1
    Join Date
    Jul 2010
    Posts
    71
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default More than one forms

    Hello
    How can I create more than one forms ( .ui ) by using a qt creator.

    If you press the button in first form ===> I watch the second form.

    Thank you

  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: More than one 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.


  3. #3
    Join Date
    Jul 2010
    Posts
    71
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: More than one forms

    Do you work this with the qt creator?
    I want a simple example of this

  4. #4
    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: More than one forms

    Qt Creator is a text editor. You may input the code using any text editor you want.
    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.


  5. #5
    Join Date
    Jul 2010
    Posts
    71
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: More than one forms

    Quote Originally Posted by wysota View Post
    Qt Creator is a text editor. You may input the code using any text editor you want.

    This method does not work with .ui

    I want a simple example of communication between the Forms.

  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: More than one forms

    Quote Originally Posted by NewLegend View Post
    This method does not work with .ui
    Of course it does. Of course, as always, you need to deploy the classes generated from ui files to widgets first but I'm sure you already know that.
    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
    Jul 2010
    Posts
    71
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: More than one forms

    Quote Originally Posted by wysota View Post
    Of course it does. Of course, as always, you need to deploy the classes generated from ui files to widgets first but I'm sure you already know that.
    Become a Generous, and do me a simple example.
    Last edited by NewLegend; 13th September 2010 at 23:51.

  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: More than one forms

    You are able to start a new project with Qt Creator based on QMainWindow or QDialog right ? (Use File - New - Qt QUI Application).

    In your project, do again File - New - Qt - Designer Form Class. This way you create the files (ui, cpp, header) for your second form.

    Put a button on your first form, and in the 'clicked()' slot you just put the following code :

    Qt Code:
    1. CMySecondForm *pSecondForm = new CMySecondForm ( this );
    2. pSecondForm ->exec();
    3. delete pSecondForm ;
    To copy to clipboard, switch view to plain text mode 

    This creates an instance of your second form, and shows it. Of course you have to include the header of your second form in the cpp file of your first form.

    Best regards,
    Marc

  9. #9
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: More than one forms

    @Marc, nice tutorial, only one small correction: you should not delete the second dialog pointer, because you gave it a parent (the "this" pointer - which is a pointer to the mainwindow in this case)

  10. #10
    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: More than one forms

    Quote Originally Posted by NewLegend View Post
    Become a Generous, and do me a simple example.
    You have been given all the code you need! What more do you want!? Do you want me to paste the code from the FAQ into my post? Will that make any difference to you? If you are not able to create a widget with Creator then don't use it and code your widgets manually. If you are able to create a widget with Creator, then just combine it with code from the FAQ. If you don't know how to create a widget then maybe you should focus on that first instead of trying to create two widgets...
    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.


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

    Default Re: More than one forms

    Hi Zlatomir,

    Now I have a question...

    If I don't want the second form to live any longer then the time needed to show the dialog (e.g. for a modal dialog), what do I do then ? Just create the QDialog without a parent ? So...
    Qt Code:
    1. CMySecondForm *pSecondForm = new CMySecondForm();
    2. pSecondForm->exec();
    3. delete pSecondForm;
    To copy to clipboard, switch view to plain text mode 
    I assumed that the parent was also needed for the operating system to know what windows are related (e.g. if you minimize the main window that all child windows are minimized also). But maybe my assumption is wrong.
    There is no method of QWidget to make it delete one of its children. Maybe I could do setParent(0) of my pSecondForm and then do my own delete ?

    Best regards,
    Marc

  12. #12
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: More than one forms

    In case of a modal dialog, you can allocate on stack
    and if you have created one with default buttons do some of this:
    Qt Code:
    1. void MainWindow::slot_connected_with_button_s_clicked (){
    2. secondModalDialog dlg(this);
    3.  
    4. if (dlg.exec() == Accepted) {
    5. //do the work if user clicked "Ok" on your modal dialog;
    6. }
    7. }
    To copy to clipboard, switch view to plain text mode 

  13. #13
    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: More than one 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.


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

    Default Re: More than one forms

    Sorry...

    Zlatomir, I just should'nt have put the delete in my code because the OP probably didn't want the second form to be modal. Your remark got me side-tracked about what would happen if the parent would try and delete a child that I already deleted myself. But that's no problem I guess. Probably the destructor of the child notifies the parent that it is being deleted and it gets removed form the list of children.

    @NewLedgend : so just don't do the delete.... and read the FAQ ...

    Best regards,
    Marc

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

    Post Re: More than one forms

    Quote Originally Posted by NewLegend
    Hello
    I've tried more than once to no avail.
    More than a 10 mistakes out to me.

    Saturday is the deadline for delivery of the project.

    I beg you to make me this.
    And send me attachments form .Zip
    It will not take time.

    Please
    Please
    Please
    Please
    Here you go.

    The second form is 'modal'. If you need to create a non-modal form, things must be done a bit different. I will leave that as an excercise to you.

    Non-modal forms are not really really easy, because you must make sure that you don't create the second form multiple times. But that's just a C/C++ technique that you should learn.

    And please ... please ... please ... next time just say what the error is you are getting instead of asking someone to do it for you

    Best regards,
    Marc
    Attached Files Attached Files

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

    takechi (11th October 2010)

  17. #16
    Join Date
    Jul 2010
    Posts
    71
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: More than one forms

    Thank you
    In modal form, Can I send the values from the second form to the first ???
    Last edited by NewLegend; 15th September 2010 at 00:20.

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

    Default Re: More than one forms

    That depends.

    If you know C/C++, then you can.

    Best regards,
    Marc

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. Designer Forms
    By srohit24 in forum Qt Programming
    Replies: 8
    Last Post: 20th July 2009, 11:28
  3. How to communicate between two forms
    By iamjayanth in forum Qt Programming
    Replies: 2
    Last Post: 7th April 2009, 08:17
  4. Connect forms
    By renia in forum Newbie
    Replies: 1
    Last Post: 16th March 2009, 17:31
  5. Layouting "Windows.Forms" like Qt forms
    By Boron in forum Qt Tools
    Replies: 1
    Last Post: 29th April 2008, 22:01

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.