Best practice for a Qt application with multiple UIs in C++
The case is as follows:
You have a main window (ui1) that is to contain two other UIs (ui2 and ui3). Neither ui2 nor ui3 care about any 开发者_如何学编程other uis. They only have slots to react to, and they might emit signals as well. See drawing below.
+----------------------------+
| +------+ +------+ |
| | | | | |
| | | | | |
| | | | | |
| | ui2| | ui3| |
| +------+ +------+ |
| |
| ui1 |
+----------------------------+
ui1 is loaded by AppWindow class and is used like this:
...
int main(int argc, char *argv[])
{
CustomApp app(argc,argv);
AppWindow w;
w.show();
return app.exec();
}
What is a recommended way of creating the AppWindow class? Any simple example?
Thanks
When creating ui1
, drag two basic widgets (i.e. QWidget
) into the UI. Then, in designer, you can right click and choose Promote To ...
. Within that dialog specify the "Promoted class name" and the "Header file" that correspond to ui2
and ui3
.
You won't be able to see a live preview using this method, but when the header and class name are specified correctly it will compile and work correctly.
精彩评论