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. How to pass SIGNAL parameter(s) to SLOT as SAME parameters ?
Forum Updated to NodeBB v4.3 + New Features

How to pass SIGNAL parameter(s) to SLOT as SAME parameters ?

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

    Could somebody please hep me to understand how it physically works ?

    I do not need another explanation about how to use or not to use "go to slot " or connect or lambda....

    I do not understand how SIGNAL acquires these parameters and how they are passed to SLOT.
    When I posted my prevision "go to slot" question I got confused with usage of parameters because they were added to SLOT , not to SIGNAL.

    Now I am asking the opposite -
    how does SIGNAL process / acquire the parameters,
    ( could I have a debug somewhere to actually read the SIGNAL and not just indirectly tracking the list changes via dummy SIGNAL / SLOT as I am doing now ?)
    and HOW to pass them to slot .

    can I envision these parameters as some kind of global variable ?

    My attached test code detects the changes in list OK, now I need to pass the actual item to another object. ( some code would be nice, but not necessary )

        connect(ui->list,
                SIGNAL(currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous)),
                this, // temp same object 
                SLOT(testSlot())   //  dummy tracking changes only need to pass QListWidgetItem * current, QListWidgetItem * previous)), here 
                );
    
    
    
    Chris KawaC 1 Reply Last reply
    0
    • A Anonymous_Banned275

      Could somebody please hep me to understand how it physically works ?

      I do not need another explanation about how to use or not to use "go to slot " or connect or lambda....

      I do not understand how SIGNAL acquires these parameters and how they are passed to SLOT.
      When I posted my prevision "go to slot" question I got confused with usage of parameters because they were added to SLOT , not to SIGNAL.

      Now I am asking the opposite -
      how does SIGNAL process / acquire the parameters,
      ( could I have a debug somewhere to actually read the SIGNAL and not just indirectly tracking the list changes via dummy SIGNAL / SLOT as I am doing now ?)
      and HOW to pass them to slot .

      can I envision these parameters as some kind of global variable ?

      My attached test code detects the changes in list OK, now I need to pass the actual item to another object. ( some code would be nice, but not necessary )

          connect(ui->list,
                  SIGNAL(currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous)),
                  this, // temp same object 
                  SLOT(testSlot())   //  dummy tracking changes only need to pass QListWidgetItem * current, QListWidgetItem * previous)), here 
                  );
      
      
      
      Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      SIGNAL(currentItemChanged(QListWidgetItem * current, QListWidgetItem * previous))

      This code is not valid. You don't pass parameter names to SIGNAL macro, only the types. It should be SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*))

      how does SIGNAL process (...) parameters

      SIGNAL macro just stringifies the function name and parameters, so if you have a void something(int) signal it creates a string in a unified format like "2something(int)" (just an example, the actual format of that string is internal and not important to you). Same goes for the SLOT macro. Internally connect uses these strings to match function signatures. If, for educational reasons, you're curious what the format of that string is you can just write it out:

      qDebug() << SIGNAL(currentItemChanged(QListWidgetItem*, QListWidgetItem*));
      

      how does SIGNAL (...) acquire parameters
      and HOW to pass them to slot .

      The code that emits that signal just passes them, so for example some function in the QListWidget will have:

      void QListWidget::something()
      {
         ...
         QListWidgetItem* current  = ...;
         QListWidgetItem* previous  = ...;
         emit currentItemChanged(current, previous);
         ...
      }
      

      Emiting a signal like emit someSignal(42) is conceptually something like this (in pseudo code). This is what moc generates as the function body of that signal:

      void someSignal(int param)
      {
          foreach (connected_slots)
          {
            if (stringified_signature_of_signal matches stringified_signature_of_slot)
               slot(param);
          }
      }
      

      can I envision these parameters as some kind of global variable ?

      I'm not sure what you mean. You're getting them in the slot so you can see them there. If you want to inspect them before the signal is emitted just set a breakpoint where the signal is emitted. In your example you ignore signal parameters. If you want to inspect them in the slot you need to change the slot signature to receive them:

      void testSlot(QListWidgetItem * current, QListWidgetItem * previous)
      

      and change your connect statement accordingly to use

      SLOT(testSlot(QListWidgetItem*, QListWidgetItem*))
      
      1 Reply Last reply
      2

      • Login

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