Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Passing data from MainWindow to Dialog window.



  • Hello.

    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?



  • you've heard of arrays?
    you understand that signals can pass parameters?



  • I've heard of arrays and signals & slots. Would you mind providing an example?


  • Lifetime Qt Champion

    @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?



  • @parameter2
    hi
    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[50];
    //for example set data to 5th dialog
        dlg[5].setDate("reza",100,...);
    

    [for add a dialog to your project:
    rightClick on your projec>add new >Qt>Qt designer form class...
    ]



  • @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.


Log in to reply