QtCreator and signals and slots
In the QtCreator change signals/slots context menu, I can't insert neither signals nor slots that have parameterized arguments such as: QList<QString>, etc. or even references only re开发者_JAVA技巧gular types (int, QSring, etc.)
Why?
When you connect a signal to a socket you use MetaType system of QObject:
connect(sender, SIGNAL(updated(QList<MyClass>), receiver, SLOT(list_updated(QList<MyClass>))
The parameter of the signal and slot is of "QList<MyClass>" metatype. Since it is custom metatype, Qt library has no knowledge of underlying implementation type.
Declare new types with Q_DECLARE_METATYPE() to make them available to QVariant and other template-based functions. Call qRegisterMetaType() to make type available to non-template based functions, such as the queued signal and slot connections.
So you need to add metatype declaration before you make connection:
qRegisterMetaType<MyClass>("MyClass");
qRegisterMetaType<QList<MyClass> >("QList<MyClass>");
精彩评论