Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
connecting two forms
how do I connect two forms. I have my main.ui form and I have another form whatever.ui if I click ok on the main form I want the whatever.ui form to pop up how do I do this?
thank Nathan
RE: connecting two forms
1. Add form1 parameter to the constructor of form2
2. Pass "this" to form2 instance created in form1
3. Create a form variable of form1 in form2 to be assign the passed instance of forma.
on form parameters u can call hide() and show() functions up on requirement.
This little bit tricky to call another form, follow the steps below,
1. Button name on the main.ui is OK.
2. Create a slot in main class of main.h file as below,
public slots:
void on_OK_clicked();
3. Write the implementation for on_OK_clicked() as below
void main::on_OK_clicked()
{
4. Create object of whatever.ui (include whatever.h in this file)
5. Call show() or exec() of whatever object acordingly
}
It will work fine. Try this.
-Segu,
one small question
Thanks for replying to this problem :-) . I followed the instructions and could follow them but am stuck at a small problem.
I have a main form, on which I have an about button, which when pressed should display another form with text on it.
This is the snippet of code in the ui.h of the main form.
void mainform::openabout()
111 {
112 aboutform f;
113 //Show the about form
114 f.show();
115 }
aboutform.ui.h has
#include <qfile.h>
13
14 void aboutform::init()
15 {
16 //do nothing
17 }
in the pro file .ui files listed are mainform.ui aboutform.ui.
pro file has
TEMPLATE = app
2 LANGUAGE = C++
3
4 CONFIG += qt warn_on release
5
6 SOURCES += main.cpp
7
8 FORMS = mainform.ui aboutform.ui
9
10 unix {
11 UI_DIR = .ui
12 MOC_DIR = .moc
13 OBJECTS_DIR = .obj
14 }
I created the openabout slot by using the connection editor and when the about button is clicked the openabout function is executed. The code compiles fine, with qmake and make, but I don't see a binary for aboutform!! and so when I click the about button the second form does not show.
Is there some obvious mistake that I have committed. Do I have to separately compile aboutform?
Thanks in advance,
-A
a little help please
Guys, if someone can see a mistake in my code (attached in the previous post)...please help me out.
Thanks,
-A