Details
-
Bug
-
Resolution: Out of scope
-
P3: Somewhat important
-
4.4.1
-
None
Description
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 )
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"
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------