PDA

View Full Version : Signals and Slots (with structure as parameters)



vishwanath
22nd November 2006, 14:59
Hi

Is there any way to pass structure as parameters for signals and slots

thanks,
vishwa.

jpn
22nd November 2006, 15:04
Yes, Qt just has to be made aware of the type. See Q_DECLARE_METATYPE (http://doc.trolltech.com/4.2/qmetatype.html#Q_DECLARE_METATYPE) and qRegisterMetaType (http://doc.trolltech.com/4.2/qmetatype.html#qRegisterMetaType).

vishwanath
22nd November 2006, 15:17
here is my senario

I have a struct
struct SourceDoneParams_t
{
int eventType;
char* url;
};

Q_DECLARE_METATYPE(mmafwrapper::SourceDoneParams_t );

connected signal/slot something like this
connect(this, SIGNAL(applySourceDone(const mmafwrapper::SourceDoneParams_t)), this,
SLOT(onApplySourceDone(const mmafwrapper::SourceDoneParams_t)));

And I am getting error whenever signal is emmited

QObject::connect Cannot Queue arguments of type 'mmafwrapper::SourceDoneParams_t'

jpn
22nd November 2006, 15:24
From Q_DECLARE_METATYPE (http://doc.trolltech.com/4.2/qmetatype.html#Q_DECLARE_METATYPE):

Note that if you intend to use the type in queued signal and slot connections, you also have to call qRegisterMetaType() (http://doc.trolltech.com/4.2/qmetatype.html#qRegisterMetaType) since such connections are resolved at runtime.

jacek
22nd November 2006, 21:14
struct SourceDoneParams_t
{
...
char* url;
};
Remember that when you send something through a queued connection Qt creates a copy of it, so watch out for that pointer.