PDA

View Full Version : More than one forms



NewLegend
13th September 2010, 01:44
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

wysota
13th September 2010, 01:48
I have two forms. How to open a second form after a button is clicked in the first one? (http://www.qtcentre.org/faq.php?faq=qt_general_category#faq_qt_designer_2f orms)

NewLegend
13th September 2010, 01:56
I have two forms. How to open a second form after a button is clicked in the first one? (http://www.qtcentre.org/faq.php?faq=qt_general_category#faq_qt_designer_2f orms)

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

wysota
13th September 2010, 10:19
Qt Creator is a text editor. You may input the code using any text editor you want.

NewLegend
14th September 2010, 00:23
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.

wysota
14th September 2010, 00:30
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.

NewLegend
14th September 2010, 00:35
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.

marcvanriet
14th September 2010, 01:14
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 :


CMySecondForm *pSecondForm = new CMySecondForm ( this );
pSecondForm ->exec();
delete pSecondForm ;

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

Zlatomir
14th September 2010, 01:35
@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)

wysota
14th September 2010, 02:13
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...

marcvanriet
14th September 2010, 13:02
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...

CMySecondForm *pSecondForm = new CMySecondForm();
pSecondForm->exec();
delete pSecondForm;
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

Zlatomir
14th September 2010, 13:10
In case of a modal dialog, you can allocate on stack
and if you have created one with default buttons do some of this:


void MainWindow::slot_connected_with_button_s_clicked (){
secondModalDialog dlg(this);

if (dlg.exec() == Accepted) {
//do the work if user clicked "Ok" on your modal dialog;
}
}

wysota
14th September 2010, 13:24
Guys, look into the FAQ please :)

I have two forms. How to open a second form after a button is clicked in the first one? (http://www.qtcentre.org/faq.php?faq=qt_general_category#faq_qt_designer_2f orms)

marcvanriet
14th September 2010, 22:34
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

marcvanriet
15th September 2010, 00:23
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 :mad:

Best regards,
Marc

NewLegend
15th September 2010, 01:07
Thank you
In modal form, Can I send the values from the second form to the first ???

marcvanriet
15th September 2010, 01:32
That depends.

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

Best regards,
Marc