PDA

View Full Version : Switching between 2 Forms



strateng
4th June 2010, 06:32
Hey,

I was looking at the following link:

http://www.qtcentre.org/threads/27255-Multiple-Forms-Handling

I wasn't able to get the 2 forms switching with a button.

sudhansu suggested:
create a pointer to form2 in form1 class. allocate memory in constructor.
inside button_on_click slot "call pointer->show();"

I think I may have done this incorrectly, would someone be able to show an example of what I should have coded for that section sudhansu suggested?

Thanks,
Strateng

tbscope
4th June 2010, 06:42
What do you mean with form switching?
Your post and the one you refer to don't explain this.

Do you want to have a button on form 1 and when clicking on it show form 2?
Do you also want to have a button on form 2 and when clicking on it show form 1?

strateng
4th June 2010, 07:13
Thanks for the reply tbscope.

Oh sorry I thought the one I was referring to actually explained it but I would like a button on form 1 when I click it to show form 2.

At the moment I thought I could use the following code but it doesn't work
Form2 f2;
f2.show();

Thanks,
Strateng

tbscope
4th June 2010, 07:21
The following code is pseudo code (as it may contain syntax errors). It's just to give you an idea.
It also assumes you have a form 1 with a button on it.


Class Form1 : public QDialog
{
Q_OBJECT

public:
Form1(QWidget *parent = 0);

private:
Form2 *mySecondForm;
};


Form1::Form1(QWidget *parent) : Dialog(parent)
{
// standard ui setup here...

mySecondForm = new Form2(this);

connect(ui->buttonShowForm2, SIGNAL(clicked()), mySecondForm, SLOT(show()));
}

Try something like that.

strateng
4th June 2010, 07:44
Thanks for your reply but sadly I am still unable to get to the other form using similar sample coding you provided.

Thanks,
Strateng


The following code is pseudo code (as it may contain syntax errors). It's just to give you an idea.
It also assumes you have a form 1 with a button on it.


Class Form1 : public QDialog
{
Q_OBJECT

public:
Form1(QWidget *parent = 0);

private:
Form2 *mySecondForm;
};


Form1::Form1(QWidget *parent) : Dialog(parent)
{
// standard ui setup here...

mySecondForm = new Form2(this);

connect(ui->buttonShowForm2, SIGNAL(clicked()), mySecondForm, SLOT(show()));
}

Try something like that.

ChrisW67
4th June 2010, 09:07
Thanks for your reply but sadly I am still unable to get to the other form using similar sample coding you provided.
How about you put a little effort in to explaining exactly how you are trying to do it, what does and does not happen etc. Post a short example that demonstrates what you are doing and how that fails. We could spend a small eternity playing guessing games otherwise.

wysota
4th June 2010, 09:09
http://www.qtcentre.org/faq.php?faq=qt_general_category#faq_qt_designer_2f orms