May 26, 2011

Jakob Schou Jakob Schou
Lab Rat
25 posts

QSharedPointer<UserDataType> as signal/slot parameters

 

In general a user data type should be registered with the meta system in order to be used as parameters in signal/slot queued communication. How about a QSharedPointer to a user data type. Is that safe? Does it matter if the user data type is registered?

If QSharedPointer can’t be used I suppose a raw pointer would be ok (provided I can manage the lifetime of the object correctly). Right?

Thanks

4 replies

May 26, 2011

Andre Andre
Area 51 Engineer
6031 posts

You should be able to use it as a parameter ok, I think, especially if your signal-slot connections are direct and not queued.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

May 26, 2011

Jakob Schou Jakob Schou
Lab Rat
25 posts

The connection in question is queued.

May 26, 2011

Andre Andre
Area 51 Engineer
6031 posts

In that case, I think you need to register them. Make a typedef for QSharedPointer<UserDataType>, and use both Q_DECLARE_METATYPE as well as qRegisterMetaType() to register it for use.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

May 26, 2011

Franzk Franzk
Lab Rat
830 posts

Andre wrote:
In that case, I think you need to register them. Make a typedef for QSharedPointer<UserDataType>, and use both Q_DECLARE_METATYPE as well as qRegisterMetaType() to register it for use.

Correct. The Q_DECLARE_METATYPE macro is necessary in both cases. qRegisterMetaType is required for the queued connection.

 Signature 

“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields

http://www.catb.org/~esr/faqs/smart-questions.html

 
  ‹‹ How to close first windows , and open different window but in the same application (like Skype)      Apply QGraphicsBlurEffect to a window ››

You must log in to post a reply. Not a member yet? Register here!