Results 1 to 8 of 8

Thread: problem with qvariant_casting to a usertype

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2006
    Posts
    849
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    6
    Thanked 163 Times in 151 Posts

    Default Re: problem with qvariant_casting to a usertype

    please show us your code where you declare your custom variant type and where you use it

  2. #2

    Default Re: problem with qvariant_casting to a usertype

    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:
    1. #pragma once
    2. #include "ViewStateInfo.hpp"
    3.  
    4.  
    5.  
    6. namespace composer
    7. {
    8. namespace model
    9. {
    10. //
    11. //
    12. //
    13. class LabelStateInfo : public ViewStateInfo
    14. {
    15. public:
    16.  
    17. LabelStateInfo(); // constructor
    18.  
    19.  
    20. // [...]
    21.  
    22. private:
    23. };
    24. }
    25. }
    26. Q_DECLARE_METATYPE(composer::model::LabelStateInfo*)
    To copy to clipboard, switch view to plain text mode 

    David

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: problem with qvariant_casting to a usertype

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4

    Default Re: problem with qvariant_casting to a usertype

    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

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: problem with qvariant_casting to a usertype

    Yes, but without seeing the actual code it is hard to say what you did wrong.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6

    Default Re: problem with qvariant_casting to a usertype

    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+

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: problem with qvariant_casting to a usertype

    Can you show us the exact code you use?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 15:38
  2. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 10:12
  3. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 09:47
  4. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 11:35
  5. Replies: 16
    Last Post: 7th March 2006, 16:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.