Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3007

QMetaObject::connectSlotsByName with overloaded signals

XMLWordPrintable

      When using QMetaObject::connectSlotsByName, the Meta Object Compiler has problems making the correct Signal->Slot connections when using overloaded signals. Test with example code provided to see wrong Signal connected to Slot. Change the name of one of the signals, and both are connected properly.

      //------------------------------------------------------------------------------
      //------------------------------------------------------------------------------

      #include <QtCore/QDebug>
      #include <QtCore/QObject>
      #include <QtCore/QMetaType>

      //------------------------------------------------------------------------------
      //------------------------------------------------------------------------------

      typedef QString Flag;
      typedef int Flags;

      Q_DECLARE_METATYPE( Flag );
      Q_DECLARE_METATYPE( Flags );

      //------------------------------------------------------------------------------
      //------------------------------------------------------------------------------

      class Father : public QObject
      {
      Q_OBJECT
      public:
      Father( QString n, QObject * p = NULL ) :
      QObject( p )

      { setObjectName( n ); }
      private slots:
      void on_child_sig( Flag flag )
      { qDebug() << __PRETTY_FUNCTION__ << flag; }
      void on_child_sig( Flags flags )
      { qDebug() << __PRETTY_FUNCTION__ << flags; }
      };

      //------------------------------------------------------------------------------
      //------------------------------------------------------------------------------

      class Child : public QObject
      {
      Q_OBJECT
      public:
      Child( QString n, QObject * p ) :
      QObject( p )
      { setObjectName( n ); }

      void emitIt()

      { Flag flag = "une chaine"; bool test = true; qDebug() << __PRETTY_FUNCTION__ << "emit sig(" << flag << "," << test << ")"; emit sig( flag, test ); qDebug() << __PRETTY_FUNCTION__ << "emitted sig(" << flag << "," << test << ")"; Flags flags = 2; qDebug() << __PRETTY_FUNCTION__ << "emit sig(" << flags << ")"; emit sig( flags ); qDebug() << __PRETTY_FUNCTION__ << "emitted sig(" << flags << ")"; }

      signals:
      void sig( Flags ); // ce signal est connecte
      void sig( Flag, int ); // ce signal devrait etre connecte
      };

      //------------------------------------------------------------------------------
      //------------------------------------------------------------------------------

      int main ( int, char * * )
      {
      Father * father = new Father( "father" );
      Child * child = new Child( "child", father );

      QMetaObject::connectSlotsByName( father );

      child->emitIt();

      delete father;
      }

      //------------------------------------------------------------------------------
      //------------------------------------------------------------------------------

      #include "main.moc"

      //------------------------------------------------------------------------------
      //------------------------------------------------------------------------------

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            ogoffart Olivier Goffart (Woboq GmbH)
            janichol Andy Nichols
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes