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 5.1k 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 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?

    dream_captainD jsulmJ 2 Replies Last reply
    0
    • L Lasith

      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?

      dream_captainD Offline
      dream_captainD Offline
      dream_captain
      wrote on 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

        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?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on 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

        • Login

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