How can I create multiple, distinct instances of the same user instance represented by a .ui file?
-
Hello and thanks for taking the time,
In my application I need many (>40) instances of the same form, but at the same time each instance should maintain a distinct status (in terms of its contents, i.e. checkboxes etc.).
If I create a single .ui file instead of a .ui file per instance (they have a slightly different function, so also different names but functionally they are the same), the user interface ingredients are no longer unique so instances impact one another. On the other hand, having multiple .ui files seems redundant and wasteful.
If there a way to do this using one .ui file to represent multiple instances?
Thanks in advance. -
@tamirmichael
Hi,
I suppose that for your Form you have (for example):
a MyForm.ui
a MyForm class that is declared in MyForm.h and MyForm.cpp filesSo, an one a possible way is:
MyForm *form1 = new MyForm(this);
MyForm *form2 = new MyForm(this);You can declare functions to customize every instance, for example:
form1->setCustom1();
form2->setCustom2();or
form1->setCustom( mode1 );
form2->setCustom( mode2 );You can send a signal from instance to other instance, for example
connect( form1, &MyForm::sendData, form2, &MyForm::receiveData );
connect( form1, &MyForm::sendData, form2, &MyForm::receiveData );Made for two, made for N instances ;)
Note: do not use static variables in your MyForm for customization.
-
Hi,
Out of curiosity, do you really need that many instances of your widget ?
It looks like using the model view paradigm might simplify your UI handling.
-
Thank you for replying. The actual reason for the problem is not the optimization I implemented (i.e. removing the majority of the .ui files) but due to actively, explicitly resetting the checkboxes...problem solved, all is good!