please show us your code where you declare your custom variant type and where you use it
please show us your code where you declare your custom variant type and where you use it
Hi caduel,
I do it quite the usual way I guess. ViewStateInfo derives from QObject somewhere up in the inheritance chain. Thanks for taking a look mate.
So this is the header of the usertype.
Qt Code:
#pragma once #include "ViewStateInfo.hpp" namespace composer { namespace model { // // // class LabelStateInfo : public ViewStateInfo { public: LabelStateInfo(); // constructor // [...] private: }; } } Q_DECLARE_METATYPE(composer::model::LabelStateInfo*)To copy to clipboard, switch view to plain text mode
David
QVariant can accept pointers to QObject right out of the box so you don't have to declare the metatype for your own class - you can store it normally and then after retrieving it, cast it to proper type.
Hi Wysota, thanks for your reply.
I will try what you proposed once Im at home. I didnt know that and it sounds like a good idea especially because I have a templated wrapper to the qvariant casting in my app already.
Out of curiosity: In theory what I was trying to do should work, shouldnt it?
Cheers,
David
Yes, but without seeing the actual code it is hard to say what you did wrong.
Hi, sorry but I like to bring this up again (as I hate unsolved problems and the proposed workaround of using QObjects would pose some nasty additional expenses on client code side):
The thing is, that the qmetatype registration obviously seems to work because my type has an id(257) which is successfully retrieved within qvariant_cast. So if you register a couple of usertypes shouldnt they get all an id from 256+ ?
I try to find out whether the usertype registration is working or not. And from what I see it is working. And if it is working then there really isnt anything else I can do wrong, isnt there?
David
P.S.: does somebody understand the == comarison in line 4 of the initial code snippet and explain it to me? I would expect it to be >= since there isnt only one usertype of id 256 qvariant_cast may cast to, but there are any numbers 256+
Bookmarks