HOW TO...add vaiable to (C++) class definition
-
i like to have SINGLE QDialog ( subroject )
and be able to have multiple forms attached / selectable to this single object.i other words
how to modify QDialog class to pass a index to be able to imlement such index to use specific form.Here is "standard" QDialog code :
Dialog::Dialog(QWidget *parent) : QDialog(parent) , ui(new Ui::Dialog) builds single form { ui->setupUi(this); builds single form test access to form TOK text = " Inotial accesas from constructor (app) "; ui->textEdit->append(text); }
How do I "add index " to it and replace single , ui(new Ui::Dialog)?
I need a real code or an example to ADD / pass an "index" as variable to C++ class.
THANKS -
@AnneRanch said in HOW TO...add vaiable to (C++) class definition:
How do I "add index " to it and replace single , ui(new Ui::Dialog)?
As is so often the case, it is difficult to find out what's the idea behind all this and how we could help.
And also as almost always, your topic title is somewhat off your actual problem, which makes it even more difficult to provide an appropriate answer.I'm trying:
So you want multiple instances (= "copies") of yourDialog
UI in a single class?!
The way you thought of is terrible design and probably very hard to maintain.
If you plan to use the same UI multiple times:
Either create multiple instances of your dialog's content as widgets in a loop and put them in some container likeQList
orQVector
. Then you can access them by index
OR
Just spawn multiples of yourQDialog
directly and also put them in some container before.If you are thinking of
Dialog
having different versions of "UI" and you want to switch between them (by your "index"), better use
UiLoader
or use aQStackedWidget
as main widget for yourDialog
and add your "UIs" as page widgets to it.
QStackedWidget
also provides indices to select a matching page at runtime.(See this topic here)
I need a real code
What is unreal code anyway?! :)
example to ADD / pass an "index" as variable to C++ class.
This and your topic title would lead to something like this:
Dialog::Dialog(int index, QWidget *parent) : QDialog(parent) , index_(index) , ui(new Ui::Dialog)
but I dont think that's all your issue is about...