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. sending variables dynamically using signals and slots

sending variables dynamically using signals and slots

Scheduled Pinned Locked Moved Solved General and Desktop
qtcreatorsignals&slotsdynamicvariable
3 Posts 3 Posters 4.8k Views
  • 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.
  • L Offline
    L Offline
    Lasith
    wrote on 28 Nov 2017, 01:59 last edited by Lasith
    #1

    In my qt c++ I have several variables that are generated dynamically(using a for loop whose upper limit taken as user input) I want to send them to another cpp file using signal and slot mechanism! How can I achieve it?

    D J 2 Replies Last reply 28 Nov 2017, 02:59
    0
    • L Lasith
      28 Nov 2017, 01:59

      In my qt c++ I have several variables that are generated dynamically(using a for loop whose upper limit taken as user input) I want to send them to another cpp file using signal and slot mechanism! How can I achieve it?

      D Offline
      D Offline
      dream_captain
      wrote on 28 Nov 2017, 02:59 last edited by dream_captain
      #2

      @Lasith
      Please, clarify what do mean by "several items dynamically". Do they have the same type?
      Something like?:

      int upperBound =10
      for (int i = 0; i != upperBound; ++i){
          //send i to another class
      }
      
      1 Reply Last reply
      0
      • L Lasith
        28 Nov 2017, 01:59

        In my qt c++ I have several variables that are generated dynamically(using a for loop whose upper limit taken as user input) I want to send them to another cpp file using signal and slot mechanism! How can I achieve it?

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 28 Nov 2017, 05:23 last edited by
        #3

        @Lasith Well, emit a signal, pass the current value to it as parameter. Connect the signal to the slot.

        // somewhere in your code 
        connect(this, SIGNAL(mySignal(int)), otherObject, SLOT(mySlot(int)));
        for (int i = 0; i < 10; ++i)
        {
            emit mySignal(i);
        }
        
        // In the other class
        void MyObject::mySlot(const int value)
        {
            // Do something
        }
        

        Did you read http://doc.qt.io/qt-5.9/signalsandslots.html ?

        Actually you should think about the need of signals and slots in this particular case - maybe it will be much easier and faster to directly call a method from the other class instead of emitting a signal? Signals/slots are useful if you want to have loose coupling, so the sender does not need to know anything about receiver.

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

        1 Reply Last reply
        4

        1/3

        28 Nov 2017, 01:59

        • Login

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