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. [Solved] Accessing the data of one form to another form
Forum Updated to NodeBB v4.3 + New Features

[Solved] Accessing the data of one form to another form

Scheduled Pinned Locked Moved General and Desktop
13 Posts 4 Posters 5.9k 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.
  • S Offline
    S Offline
    Swinetha
    wrote on last edited by
    #1

    hai,

    I have created 5 forms like read1,read2,read3,read4 and read_main.
    read1,read2,read3,read4 having the QComboBox. In this QComboBox added multiple options but all are having one similar option like "ALL". If I select ALL option from any ui window(read1,read2,read3,read4 ) It will open the read_main window and pass the related data to this read_main window. I would like to pass the data using connect() function. but my question is how can I choose the data is coming from the which form in read_main window?
    can any one have an idea about this

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Well, there is a way to "ask" in the slot which object "send" the signal. It's not really Object orientated though, so not so great to use, but sometimes handy. It's based on the Qt Meta Object class and related QObject stuff.
      @QObject * QObject::sender() const [protected]@
      I would recommend using a different kind of way. Maybe in the constructor give every form a enum value and add this enum value into the signal. It totally depends on the application your writing.

      Greetz, Jeroen

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Swinetha
        wrote on last edited by
        #3

        could you explain me something about this I cann't get any thing

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          Hmm,
          In every form generate a signal adding a "value" to indicate the sending object. e.g. in your read1 form:
          @emit SelectedAll(READ_MAIN::FORM_1);@
          And in your main_read:
          @//Slot to catch the signal
          connect (read1, &SelectedAll, this, &HandleSelectedAll);
          ...
          void main_read(READ_MAIN eValue)
          {
          .. Do you clicked all stuff where eValue hold the form number..
          }
          @
          That's about it and is basic signal/slot stuff. The big advantage of Qt signal/slots it is thread safe and multiple connections are easily made.

          The second option I described is more complex and needs more understanding of QObject and the MOC compiler in Qt. Therefor I would not recommend it! Still, you asked for it. Again connect all the signals to the main_read slot, but then without the arguments.
          In your form constructors:
          @
          this->setProperty("Name", "Form1");
          @
          In your main_read slot do the following:
          @
          void main_read(void)
          {
          QObject * ObjectSender;
          ObjectSender = sender(); // this should return the pointer to the sending object.
          if (Sender != NULL)
          {
          if (sender->property("Name") == Form1)
          .. it was form1 how triggered the slot
          }
          }
          @
          -- Didn't test this code, but should look something like this --
          But AGAIN, it's not object orientated minded this option because the receiving class must know the name of the other objects causing dependencies between classes.
          Hope this helps a bit,

          Greetz, Jeroen

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Swinetha
            wrote on last edited by
            #5

            I am a bit confusion with both the things please once again explain me

            1 Reply Last reply
            0
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              Oke, I reread your first post, but if I understand correct you want to copy some data from the first form and place it in the read_main form? You could define a class and add this to the Q_DECLARE_METATYPE(<type>) option and add this as argument in your signal/slot connection, but why do you want to "know" who issued the signal? Do you also want to update the data of the read1 form etc from the form read_main?
              The thing to do is connect all readx form signals to a single slot in your read_main form.
              Read the signal/slot document how to do the connect() function properly.
              Btw this is done in code!! Not in designer. Designer only converts your forms to compiler readable code, that's all. but if all forms are the same, you only need 1 form that has multiple instances in your MainWindow (or other QWidget class).
              Can't make it more clear in text without deep going conversation about design techniques, Qt creator, designer and QObject.

              Greetz, Jeroen

              1 Reply Last reply
              0
              • S Offline
                S Offline
                Swinetha
                wrote on last edited by
                #7

                thank you for you reply.

                I don't want to copy some data from one form to other I want to send a command.

                and the problem was solved by passing an argument from readX to read_main()

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  Pawan Pal
                  wrote on last edited by
                  #8

                  I am Working QT serial port project, in my project have two main window ui,
                  I want when i push the button of second dialog box so text send to the main window text box.

                  yaa its possible but i dont get correct method of code.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    ankursaxena
                    wrote on last edited by
                    #9

                    Have u used socket ?? u can send text using socket.

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      Pawan Pal
                      wrote on last edited by
                      #10

                      I dont want to using this stuff like socket. In simple way to send text between two forms

                      Give me whole code of header file and source file and main .cpp

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        ankursaxena
                        wrote on last edited by
                        #11

                        Sorry . I misunderstood. Actually there is no use of socket.

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          Pawan Pal
                          wrote on last edited by
                          #12

                          how to use combo box in ethernet app.

                          Regards
                          Pawan pal

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            Pawan Pal
                            wrote on last edited by
                            #13

                            How write the code of combo box in TCP server client app.

                            Tanks & Regards
                            Pawan

                            1 Reply Last reply
                            0

                            • Login

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