Fisrt we create a MyDialog object. For the parameters read qt assistant. It is a great documentation.
Then we show myDialog by calling exec(). After you close the dialog window, exec() returns a value.
if (rc == QDialog::Rejected) means that you pressed Cancel. Then execute whatever you like.
In file main_window.ui.h create a slot called 'actionOpen' using qtdesigner.
To do that click on main_window, where the project files are, and then Edit > Slots...
Rename 'newSlot()' to 'actionOpen()' and insert this code :
|
Source code
|
1
2
3
4
5
6
|
void main_window::actionOpen() {
my_dialog1 myDialog(this,"unused_text_i_think_just_fill_something",true);
int rc = myDialog.exec();
if (rc == QDialog::Rejected) ...
...
}
|
As for the files not being loaded here is a sample of a project file :
|
Source code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
unix {
UI_DIR = .ui
MOC_DIR = .moc
OBJECTS_DIR = .obj
}
TEMPLATE = app
LANGUAGE = C++
CONFIG += qt warn_on release
HEADERS += notes.h
SOURCES += main.cpp
FORMS = Form1.ui \
Form2.ui \
MainForm.ui
IMAGES = images/1.png \
images/2.png \
images/3.png
|
You can change the project file using a text editor.
UI_DIR holds .h and .cpp files.
MOC_DIR holds moc_*.cpp files.
OBJECTS_DIR holds .o files.
HEADERS holds the .h you use in qtdesigner.
SOURCES holds the .cpp files you use in qtdesigner (usually the file main.cpp).
FORMS holds the .ui files you use in qtdesigner.
IMAGES holds the image collection.
As wysota said, when you run make, uic and moc create the files you want.
uic reads .ui files and genetares .h and .cpp files.
moc reads the generated .h files and then generates moc_*.cpp files.
Finally you get the .o files and the executable of course.
In a generated .cpp there is the corresponding include for .ui.h.
I mean in form1.cpp there is a '#include "form1.ui.h"'.
You can change the generated .h and .cpp files but then you will work with form1.ui.h, form1.h and form1.cpp.
After making changes, keep in mind that you should not use the generated makefile because all your changes in .h and .cpp files will be lost.
Compile the files on your own every time or change the makefile...
Personally I use only qtdesigner. I create the forms, add code to .ui.h and run qmake and make. It is possible to use c/c++ code within qtdesigner. Such as functions from stdlib.h e.t.c.