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. Using Qt::connect(), get senders type

Using Qt::connect(), get senders type

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 831 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.
  • ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by
    #1

    Hello,

    I have 3 objects derived from same base class,

    Com c;
    Mov m;
    Sub s;

    in that base classe there is a SIGNAL connectedChanged(bool)

    I want to connect that SIGNAL to a SLOT of another object :

       QObject::connect(&c,SIGNAL(connectedChanged(bool)),&logger,SLOT(writeLog(bool)));
       QObject::connect(&m,SIGNAL(connectedChanged(bool)),&logger,SLOT(writeLog(bool)));
       QObject::connect(&s,SIGNAL(connectedChanged(bool)),&logger,SLOT(writeLog(bool)));
    

    can my writeLog(bool) know who is the sender c ? m ? or l ?

    Thx

    1 Reply Last reply
    0
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      QObject::sender()->metaObject()->className()

      1 Reply Last reply
      1
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        change writeLog to writeLog(bool,const QString&)

        QObject::connect(&c,&BaseClass::connectedChanged,&logger,std::bind(&LoggerClass::writeLog,&logger,std::placeholders::_1,QStringLiteral("c"));
        QObject::connect(&m,&BaseClass::connectedChanged,&logger,std::bind(&LoggerClass::writeLog,&logger,std::placeholders::_1,QStringLiteral("m"));
        QObject::connect(&s,&BaseClass::connectedChanged,&logger,std::bind(&LoggerClass::writeLog,&logger,std::placeholders::_1,QStringLiteral("s"));
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        ODБOïO 1 Reply Last reply
        4
        • VRoninV VRonin

          change writeLog to writeLog(bool,const QString&)

          QObject::connect(&c,&BaseClass::connectedChanged,&logger,std::bind(&LoggerClass::writeLog,&logger,std::placeholders::_1,QStringLiteral("c"));
          QObject::connect(&m,&BaseClass::connectedChanged,&logger,std::bind(&LoggerClass::writeLog,&logger,std::placeholders::_1,QStringLiteral("m"));
          QObject::connect(&s,&BaseClass::connectedChanged,&logger,std::bind(&LoggerClass::writeLog,&logger,std::placeholders::_1,QStringLiteral("s"));
          
          ODБOïO Offline
          ODБOïO Offline
          ODБOï
          wrote on last edited by
          #4

          thx @VRonin. I just saw the the new syntax..

          1 Reply Last reply
          0

          • Login

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