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 signals and slots with different parameters: Is it possible?

Connecting signals and slots with different parameters: Is it possible?

Scheduled Pinned Locked Moved General and Desktop
signal & slotsignalslotslotsconnect
3 Posts 3 Posters 5.6k 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.
  • J Offline
    J Offline
    Jorge
    wrote on 18 Jun 2015, 18:14 last edited by
    #1

    HI,
    I wish to make a connection, and I'm aware that they both must have the same type of parameter in order to work. My question is:
    Is there a way, or workaround, to this issue?
    In my project, I want to connect a simple valuechanged signal to a a slot that receives 3 QWidet parameters.
    This is the code in question:

    //OperatorLogged is a valuechanged signal, nothing weird.
    connect(login, SIGNAL(operatorLogged(int)),
                this, SLOT(createOperatorInterface(QWidget*, QWidget*, QWidget*)));
    //createOperatorInterface takes the QWidget arguments and adds them to "this" stacked layout. "This" being  the main widget, by the way.
    

    I would also like to know if using the main.cpp is the best practice, as I was taught in OOP, to work with my code. The whole issue comes from me trying to work in the main.cpp like this:

    #include "mainwidget.h"
    #include "qlogin.h"
    #include "qdispense.h"
    #include "qdispensedisplay.h"
    #include "qresult.h"
    #include <QApplication>
    #include <QCalendarWidget>
    
    int main(int argc, char *argv[])
    {
        QApplication Skylord(argc, argv);
        mainWidget mwMainWidget;
        mwMainWidget.show();
    
        QLogin *loginWidget = new QLogin;
        QDispense *dispenseWidget = new QDispense;
        QDispenseDisplay *dispenseDisplayWidget = new QDispenseDisplay;
        QResult *resultWidget = new QResult;
    
        mwMainWidget.createLogin(loginWidget);
    
        return Skylord.exec();
    }
    

    Thanks in advance.

    T 1 Reply Last reply 18 Jun 2015, 18:58
    0
    • J Jorge
      18 Jun 2015, 18:14

      HI,
      I wish to make a connection, and I'm aware that they both must have the same type of parameter in order to work. My question is:
      Is there a way, or workaround, to this issue?
      In my project, I want to connect a simple valuechanged signal to a a slot that receives 3 QWidet parameters.
      This is the code in question:

      //OperatorLogged is a valuechanged signal, nothing weird.
      connect(login, SIGNAL(operatorLogged(int)),
                  this, SLOT(createOperatorInterface(QWidget*, QWidget*, QWidget*)));
      //createOperatorInterface takes the QWidget arguments and adds them to "this" stacked layout. "This" being  the main widget, by the way.
      

      I would also like to know if using the main.cpp is the best practice, as I was taught in OOP, to work with my code. The whole issue comes from me trying to work in the main.cpp like this:

      #include "mainwidget.h"
      #include "qlogin.h"
      #include "qdispense.h"
      #include "qdispensedisplay.h"
      #include "qresult.h"
      #include <QApplication>
      #include <QCalendarWidget>
      
      int main(int argc, char *argv[])
      {
          QApplication Skylord(argc, argv);
          mainWidget mwMainWidget;
          mwMainWidget.show();
      
          QLogin *loginWidget = new QLogin;
          QDispense *dispenseWidget = new QDispense;
          QDispenseDisplay *dispenseDisplayWidget = new QDispenseDisplay;
          QResult *resultWidget = new QResult;
      
          mwMainWidget.createLogin(loginWidget);
      
          return Skylord.exec();
      }
      

      Thanks in advance.

      T Offline
      T Offline
      t3685
      wrote on 18 Jun 2015, 18:58 last edited by
      #2

      @Jorge

      Hi,

      How would your slot know what arguments to use, i.e. which pointers to QWidgets?

      Greetings,

      t3685

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 18 Jun 2015, 20:21 last edited by
        #3

        Hi,

        Short answer: no

        The slot signature must either have the same number or less parameters than the signal and the type must be the same.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        1/3

        18 Jun 2015, 18:14

        • 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