Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved Passing data from MainWindow to Dialog window.

    General and Desktop
    5
    6
    771
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • P
      parameter2 last edited by

      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?

      mr ZX JonB 2 Replies Last reply Reply Quote 0
      • Kent-Dorfman
        Kent-Dorfman last edited by

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

        1 Reply Last reply Reply Quote 1
        • P
          parameter2 last edited by

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

          jsulm 1 Reply Last reply Reply Quote 0
          • jsulm
            jsulm Lifetime Qt Champion @parameter2 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?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 2
            • mr ZX
              mr ZX @parameter2 last edited by

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

              1 Reply Last reply Reply Quote 0
              • JonB
                JonB @parameter2 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.

                1 Reply Last reply Reply Quote 2
                • First post
                  Last post