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. Connecting Sibling Slots based on Signal Values

Connecting Sibling Slots based on Signal Values

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 515 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.
  • A Offline
    A Offline
    Anony Mouse
    wrote on last edited by
    #1

    Hi there,

    I am busy trying to figure out the best practice for coding, regarding the following:

    I have 1 sender object that generates signals and another vector of receiver objects at the same level in the hierarchy.

    I am trying to connect a signal between the two in such a way that the signal itself contains the index of the receiver object in the vector.

    Some Pseudocode will help better explain... in the parent source code I want something along the lines of:

    QObject::connect(ChildSenderObject, SIGNAL(valueChanged(index, value)),
    ChildReceiverObjectsVector[i], SLOT(changeValue(index, value)));

    where the vector index i here is the value of index argument of SIGNAL

    Currently the only solution I can think of off the top of my head is to connect them via a parent set of signals and slots like so:

    QObject::connect(ChildSenderObject, SIGNAL(valueChanged(index, value)),
    this, SLOT(findChildObject(index,value)));

    with the accompanying slot function:

    parentObject::findChildObject(index i,value v){
    ReceiverObjects[i]->changeValue(v);
    }

    So I guess my question is this: Should I be trying to connect them directly to each other or should I connect them through the parent? What is the best practice? If I can connect them directly without using a parent member function, then how exactly would I do this? Do I use a signal mapper?

    jsulmJ 1 Reply Last reply
    0
    • A Anony Mouse

      Hi there,

      I am busy trying to figure out the best practice for coding, regarding the following:

      I have 1 sender object that generates signals and another vector of receiver objects at the same level in the hierarchy.

      I am trying to connect a signal between the two in such a way that the signal itself contains the index of the receiver object in the vector.

      Some Pseudocode will help better explain... in the parent source code I want something along the lines of:

      QObject::connect(ChildSenderObject, SIGNAL(valueChanged(index, value)),
      ChildReceiverObjectsVector[i], SLOT(changeValue(index, value)));

      where the vector index i here is the value of index argument of SIGNAL

      Currently the only solution I can think of off the top of my head is to connect them via a parent set of signals and slots like so:

      QObject::connect(ChildSenderObject, SIGNAL(valueChanged(index, value)),
      this, SLOT(findChildObject(index,value)));

      with the accompanying slot function:

      parentObject::findChildObject(index i,value v){
      ReceiverObjects[i]->changeValue(v);
      }

      So I guess my question is this: Should I be trying to connect them directly to each other or should I connect them through the parent? What is the best practice? If I can connect them directly without using a parent member function, then how exactly would I do this? Do I use a signal mapper?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Anony-Mouse Your first approach is not a good solution: you would need to connect each object from the vector to the signal, but then all objects would get the signal and would then have to check the index to decide whether they should handle the signal or not.
      The second solution is better.

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

      1 Reply Last reply
      1

      • Login

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