Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Passing data from MainWindow to Dialog window.
Forum Updated to NodeBB v4.3 + New Features

Passing data from MainWindow to Dialog window.

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 1.2k Views 1 Watching
  • 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 Offline
    P Offline
    parameter2
    wrote on 30 Jan 2020, 02:32 last edited by
    #1

    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?

    M J 2 Replies Last reply 30 Jan 2020, 18:06
    0
    • K Offline
      K Offline
      Kent-Dorfman
      wrote on 30 Jan 2020, 02:40 last edited by
      #2

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

      1 Reply Last reply
      1
      • P Offline
        P Offline
        parameter2
        wrote on 30 Jan 2020, 04:45 last edited by
        #3

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

        J 1 Reply Last reply 30 Jan 2020, 06:38
        0
        • P parameter2
          30 Jan 2020, 04:45

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

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 30 Jan 2020, 06:38 last edited by
          #4

          @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
          2
          • P parameter2
            30 Jan 2020, 02:32

            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?

            M Offline
            M Offline
            mr ZX
            wrote on 30 Jan 2020, 18:06 last edited by
            #5

            @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
            0
            • P parameter2
              30 Jan 2020, 02:32

              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?

              J Offline
              J Offline
              JonB
              wrote on 31 Jan 2020, 08:29 last edited by JonB
              #6

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

              1/6

              30 Jan 2020, 02:32

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved