PDA

View Full Version : custom types for signal/slot arguments



xtofl
15th November 2011, 21:20
Hi.

In the Signals and Slots overview (http://doc.qt.nokia.com/stable/signalsandslots.html), I read that


Signals and slots can take any number of arguments of any type. They are completely type safe.

Actually trying that out, however, showed that a member function with a typedeffed argument is not recognized:





class IndexToEnum : public QObject {
Q_OBJECT
...
typedef QAudio::Mode mode;
signals:
void modeChanged( QAudio::Mode mode );
void modeChangedT( e mode );




IndexToEnum* e = new IndexToEnum;
// works just fine:
connect( e, SIGNAL( modeChanged(QAudio::Mode) ), this, SLOT( modeChanged(QAudio::Mode) ) );
// triggers "No such signal ModeEnum::modeChangedT(IndexToEnum::e)"
connect( e, SIGNAL( modeChangedT(IndexToEnum::e) ), this, SLOT( modeChangedT(IndexToEnum::e) ) );


Note: I was actually tweaking the audiodevices demo, where I wanted to insert an index->enum convertor between the modeBox and the AudioTest object.

Is this improper use of the signal/slot mechanism? Are there any other restrictions on the argument types?

stampede
15th November 2011, 21:38
void modeChangedT( e mode );
What is "e" in above code ? If its a typedef, then read here (http://doc.qt.nokia.com/stable/moc.html#moc) about limitations:

Enums and Typedefs Must Be Fully Qualified for Signal and Slot Parameters

When checking the signatures of its arguments, QObject::connect() compares the data types literally. Thus, Alignment and Qt::Alignment are treated as two distinct types. To work around this limitation, make sure to fully qualify the data types when declaring signals and slots, and when establishing connections.

So you should declare:

void modeChangedT( IndexToEnum::e );