Re: Handling multiple forms
you create form2 on the stack. When the scope is left, it is destroyed (and thus disappears.)
You have two possibilites.
i) Make it a modal dialog (ie inherit from QDialog and call exec())
ii) allocate form2 on the heap (using new, and ideally passing a QObject parent object to make sure the object gets deleted in time)
HTH
Re: Handling multiple forms
Thanks a lot caduel, i used dynamic allocation and it worked .
Still, i have one more question .
Let's say i Press de button, Form2 appears ( modally , that means i Form1 is disabled ).
I input some text into Form2's LineEdit and then i press a button, also on Form2. When I press the button, Form2 closes and Form1 becomes active again .
What I want to do now is to take the text from LineEdit on Form2 and show it somewhere in Form1 . I managed to get the actual text using a global variabile. But ... how can i detect that Form2 has closed ? For example, let's say in Form1 I also have a LineEdit. When I close Form2 , I want Form1 LineEdit to have the text from Form2 LineEdit .
How can I accomplish this ?
I tried the followind code:
Code:
void App1::button_clicked()
{
App2 *form2 = new App2(this);
form2->show();
msg.setText(text);
msg.exec();
}
hoping that the code after form2->show() would be executed after Form2 was closed.Unfortunately, the code executes as soon as Form2 appears on the screen.
Re: Handling multiple forms
override the okay() slot (if using a QDialog): store your lineedit's contents in your dialog.
at the call site (when exec() returned), call a getter-function to access that text. do not use globals for that. it is ugly and will cause you trouble. (e.g. you can not use two such dialogs that way).
Re: Handling multiple forms
could you give me an example ? i'm relative new to QT ... I don't fully understand what you explain to me ... and no .. I have a QmainWindow and a QWidget.