Results 1 to 4 of 4

Thread: Unable to define a new type with QVariant

  1. #1
    Join Date
    Feb 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Unable to define a new type with QVariant

    Can someone tell me what's wrong with the following code:

    Qt Code:
    1. GKey gg1(1, "Hi");
    2.  
    3. int id = qRegisterMetaType<GKey>("GKey");
    4.  
    5. QVariant testV(id, &gg1);
    6.  
    7. GKey gg2;
    8.  
    9. if (testV.canConvert<GKey>())
    10. gg2 = testV.value<GKey>();
    To copy to clipboard, switch view to plain text mode 
    The last line gives the following error :

    "error: no matching function for call to `GKey::GKey(GKey)"
    The GKey.h file contains :

    Qt Code:
    1. #ifndef KEY_H
    2. #define KEY_H
    3.  
    4. #include "SmartPtr.h"
    5. #include <QList>
    6. #include <QMetaType>
    7.  
    8. class GKey : public QObject
    9. {
    10. public:
    11. GKey();
    12. GKey(long type, QString uuid);
    13. virtual ~GKey();
    14.  
    15. const GKey& operator=(const GKey& key);
    16. virtual bool operator==(const GKey& key) const;
    17. virtual bool operator!=(const GKey& key) const;
    18.  
    19. inline long getType() { return type_; };
    20. void setType(long type) {type_ = type;};
    21.  
    22. inline QString getUuid() { return uuid_; };
    23. void setUuid(QString uuid) {uuid_ = uuid;};
    24.  
    25. static long getMetaNo(){ return 6000;};
    26.  
    27. explicit GKey(const GKey& key);
    28. explicit GKey(const GKey* key);
    29.  
    30. void copy(const GKey& key);
    31. void free();
    32.  
    33. void initializeGKey(long constructorType);
    34. void finishGKey(long constructorType);
    35.  
    36. protected:
    37. long type_;
    38. QString uuid_;
    39.  
    40. long constructorType_;
    41. };
    42.  
    43. Q_DECLARE_METATYPE(GKey)
    44.  
    45. typedef SmartPtr<GKey> SmartPtrGKey;
    46. typedef QList< SmartPtrGKey > SmartPtrGKeyList;
    47.  
    48.  
    49. #endif
    To copy to clipboard, switch view to plain text mode 


    Thank you !
    Last edited by jpn; 23rd February 2008 at 14:43. Reason: reformatted to look better

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Unable to define a new type with QVariant

    Why explicit copy constructor?
    J-P Nurmi

  3. #3
    Join Date
    Feb 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Windows

    Talking Re: Unable to define a new type with QVariant

    The EXPLICIT was required because I don't want to use these method when implicit conversion is required but this seems to be the problem !

    If I remove the EXPLICIT keyword, the compilation is Ok !

    I saw that my original post was edited. Is there a special procedure to follow when a post must be edited ????

    Thank you !

    Max2G

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Unable to define a new type with QVariant

    Quote Originally Posted by max2g View Post
    I saw that my original post was edited. Is there a special procedure to follow when a post must be edited ????
    I added [code] and [quote] tags to make it a bit more readable. Wrapping code snippets with [code] tags (the "#" button in editor) produces line numbers and syntax highlighting plus allows indentation, thus makes code snippets more readable. For more details: http://www.qtcentre.org/forum/misc.php?do=bbcode
    J-P Nurmi

Similar Threads

  1. odd double widgets
    By jhearon in forum Qt Programming
    Replies: 1
    Last Post: 23rd February 2008, 18:18
  2. dummy question(Error)
    By Masih in forum Qt Programming
    Replies: 12
    Last Post: 19th July 2007, 23:38

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.