Unsolved Passing data from MainWindow to Dialog window.
parameter2 last edited by
I need to have a Mainwindow with about 50 pushbuttons. Each pushbutton is supposed to open a dialog window with details of the respective signal. So each of the Dialogs would show signal name, current value, unit, temperature, and other data. All dialogs are supposed to be displayed in the same format. Short of creating a separate class and ui form for each of the signals, what would be the best way to go about getting this done?
Kent-Dorfman last edited by
you've heard of arrays?
you understand that signals can pass parameters?
parameter2 last edited by
I've heard of arrays and signals & slots. Would you mind providing an example?
jsulm Lifetime Qt Champion last edited by
@parameter2 There are ways in C++ to pass data from one class instance to another, for example:
- Constructor with parameters
- Setter methods
So, what exactly is the problem you have?
mr ZX last edited by
if I understand your question. ;)
you have many button and for response of all signals whit one slot ,you can use QSignalMapper class .
and for create many [same] dialog .add one dialog form class into your project and design and write a method like setDate(Qstring name,int Value,...) to set data from this dialog..., after use of this class in mainWindow like :
myDialog *dlg=new myDialog; //for example set data to 5th dialog dlg.setDate("reza",100,...);
[for add a dialog to your project:
rightClick on your projec>add new >Qt>Qt designer form class...
JonB last edited by JonB
@parameter2 said in Passing data from MainWindow to Dialog window.:
So each of the Dialogs would show signal name, current value, unit, temperature, and other data. All dialogs are supposed to be displayed in the same format.
Let's be clear: from what you have said, you will not want 50 distinct dialogs, so you will not want to create an array of dialogs as one poster has suggested.
It sounds like you just want one dialog with the appropriate widgets on it. On a given pushbutton click, you show the one dialog, passing in the desired parameters to fill the widgets. As @jsulm wrote earlier, you might pass those parameters to the dialog's constructor, or you might have setter methods in the dialog which you can call.
Depending on what/how you get the parameters desired to pass to the dialog from the pushbutton click, you might have 50 separate slots for the signal (one for each button, perhaps using lambdas), or (preferable to me, probably) just one slot which could e.g. look at which pushbutton is the sender of the signal to decide what to pass on to the dialog.