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. Connection after creating new object each time
Forum Updated to NodeBB v4.3 + New Features

Connection after creating new object each time

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 469 Views 3 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.
  • G Offline
    G Offline
    GunkutA
    wrote on last edited by GunkutA
    #1

    I have a button which creates a new widget every time its pressed:

    void protocolForm::on_button_graph_clicked()
    {
    
        qDebug() << VectorMap[ ui->tableWidget->item(rowFocused,0)->text()];
        graphFormInstance = new graphForm(this);
        graphFormInstance->show();
    }
    

    And I want connect a signal to all of these created objects such as:
    connect(this, &SendVectorMaptoGraph, graphFormInstace, &graphForm::receiveVectorMap);

    So it will look like :

    void protocolForm::on_button_graph_clicked()
    {
    
        qDebug() << VectorMap[ ui->tableWidget->item(rowFocused,0)->text()];
        graphFormInstance = new graphForm(this);
        graphFormInstance->show();
        connect(this, &SendVectorMaptoGraph, graphFormInstance, &graphForm::receiveVectorMap);
       
    }
    

    After this connection when I emit the signal SendVectorMaptoGraph. Will it emit the slots in the all created graphFormInstance's?

    Pl45m4P 1 Reply Last reply
    0
    • G GunkutA

      I have a button which creates a new widget every time its pressed:

      void protocolForm::on_button_graph_clicked()
      {
      
          qDebug() << VectorMap[ ui->tableWidget->item(rowFocused,0)->text()];
          graphFormInstance = new graphForm(this);
          graphFormInstance->show();
      }
      

      And I want connect a signal to all of these created objects such as:
      connect(this, &SendVectorMaptoGraph, graphFormInstace, &graphForm::receiveVectorMap);

      So it will look like :

      void protocolForm::on_button_graph_clicked()
      {
      
          qDebug() << VectorMap[ ui->tableWidget->item(rowFocused,0)->text()];
          graphFormInstance = new graphForm(this);
          graphFormInstance->show();
          connect(this, &SendVectorMaptoGraph, graphFormInstance, &graphForm::receiveVectorMap);
         
      }
      

      After this connection when I emit the signal SendVectorMaptoGraph. Will it emit the slots in the all created graphFormInstance's?

      Pl45m4P Online
      Pl45m4P Online
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @GunkutA said in Connection after creating new object each time:

      creates a new widget every time its pressed:

      @GunkutA said in Connection after creating new object each time:

      to all of these created objects

      Yes, your are right, literally.. It creates a new widget every time by overriding the old instance. So you have only one at a time...

      @GunkutA said in Connection after creating new object each time:

      Will it emit the slots in the all created graphFormInstance's?

      The connection itself emits nothing, but it ensures that this knows about the slot in graphForm.

      @GunkutA said in Connection after creating new object each time:

      connect(this, &SendVectorMaptoGraph, graphFormInstance, &graphForm::receiveVectorMap);

      There's also a signal missing.

      connect(this, &THIS_CLASS::SIGNAL, graphFormInstance, &graphForm::receiveVectorMap);
      

      (THIS_CLASS = ProtocolForm in your case)


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      G 1 Reply Last reply
      1
      • Pl45m4P Pl45m4

        @GunkutA said in Connection after creating new object each time:

        creates a new widget every time its pressed:

        @GunkutA said in Connection after creating new object each time:

        to all of these created objects

        Yes, your are right, literally.. It creates a new widget every time by overriding the old instance. So you have only one at a time...

        @GunkutA said in Connection after creating new object each time:

        Will it emit the slots in the all created graphFormInstance's?

        The connection itself emits nothing, but it ensures that this knows about the slot in graphForm.

        @GunkutA said in Connection after creating new object each time:

        connect(this, &SendVectorMaptoGraph, graphFormInstance, &graphForm::receiveVectorMap);

        There's also a signal missing.

        connect(this, &THIS_CLASS::SIGNAL, graphFormInstance, &graphForm::receiveVectorMap);
        

        (THIS_CLASS = ProtocolForm in your case)

        G Offline
        G Offline
        GunkutA
        wrote on last edited by
        #3

        @Pl45m4 But it does not close the old one. Instead creates a new object. So first one is still opened when I press the button twice

        Pablo J. RoginaP Pl45m4P 2 Replies Last reply
        0
        • G GunkutA

          @Pl45m4 But it does not close the old one. Instead creates a new object. So first one is still opened when I press the button twice

          Pablo J. RoginaP Offline
          Pablo J. RoginaP Offline
          Pablo J. Rogina
          wrote on last edited by Pablo J. Rogina
          #4

          @GunkutA said in Connection after creating new object each time:

          So first one is still opened when I press the button twice

          Do you want old one to remain open? If not it's up to you to close it before creating a new object... and thus having to worry about making the signal/slot connection just once

          Upvote the answer(s) that helped you solve the issue
          Use "Topic Tools" button to mark your post as Solved
          Add screenshots via postimage.org
          Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

          G 1 Reply Last reply
          0
          • Pablo J. RoginaP Pablo J. Rogina

            @GunkutA said in Connection after creating new object each time:

            So first one is still opened when I press the button twice

            Do you want old one to remain open? If not it's up to you to close it before creating a new object... and thus having to worry about making the signal/slot connection just once

            G Offline
            G Offline
            GunkutA
            wrote on last edited by
            #5

            @Pablo-J-Rogina I want to keep them. But what I am not sure about those signal slot connections. If I do not close the previous objects and lets say I opened 3 objects. All of them open. And I put that connect line after all of them. Will all these 3 objects be connected to that signal slot mechanism?

            Chris KawaC Pablo J. RoginaP 2 Replies Last reply
            0
            • G GunkutA

              @Pl45m4 But it does not close the old one. Instead creates a new object. So first one is still opened when I press the button twice

              Pl45m4P Online
              Pl45m4P Online
              Pl45m4
              wrote on last edited by Pl45m4
              #6

              @GunkutA

              But you still override graphFormInstance with the new instance

              @GunkutA said in Connection after creating new object each time:

              I want to keep them. But what I am not sure about those signal slot connections. If I do not close the previous objects and lets say I opened 3 objects. All of them open

              You lose access to the previous instances, if you do not store them somewhere (by adding them to e.g. QGraphicsScene or whatever you want to do with these graphs). Only because they are shown, doesn't mean, that you have access to all of them, but it still will call their slots.


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              0
              • G GunkutA

                @Pablo-J-Rogina I want to keep them. But what I am not sure about those signal slot connections. If I do not close the previous objects and lets say I opened 3 objects. All of them open. And I put that connect line after all of them. Will all these 3 objects be connected to that signal slot mechanism?

                Chris KawaC Online
                Chris KawaC Online
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @GunkutA said:

                I want to keep them. But what I am not sure about those signal slot connections. If I do not close the previous objects and lets say I opened 3 objects. All of them open. And I put that connect line after all of them. Will all these 3 objects be connected to that signal slot mechanism?

                Yes.

                Each new graphForm creates a separate object and each connection between this and those objects is a separate connection so when you emit a signal a slot in all connected objects will be called.

                1 Reply Last reply
                2
                • G GunkutA

                  @Pablo-J-Rogina I want to keep them. But what I am not sure about those signal slot connections. If I do not close the previous objects and lets say I opened 3 objects. All of them open. And I put that connect line after all of them. Will all these 3 objects be connected to that signal slot mechanism?

                  Pablo J. RoginaP Offline
                  Pablo J. RoginaP Offline
                  Pablo J. Rogina
                  wrote on last edited by
                  #8

                  @GunkutA said in Connection after creating new object each time:

                  This is a basic programming concept. If you have only a variable to hold a pointer, every time a new object is created (you've got a address) that only variable will point to the new recently created object.

                  I want to keep them.

                  So you need a data structure capable of holding several pointers at the same time. Again, this is a basic programming concept.

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  3

                  • Login

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