Results 1 to 6 of 6

Thread: Registering classe in QMetaType

  1. #1
    Join Date
    Apr 2007
    Location
    Brazil
    Posts
    8
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Registering classe in QMetaType

    Hi,

    I am trying to register a class on QMetaType in order to use it with QVariant. However, when I try to compile the class with the macro Q_DECLARE_METATYPE occurs an error.

    Here is the code:

    Qt Code:
    1. #include "Account.h"
    2.  
    3. Account::Account() {
    4. // do nothing
    5. };
    6.  
    7. Account::Account(QString _provider, QString _type, QPixmap _icon) {
    8. provider = _provider;
    9. type = _type;
    10. icon = _icon;
    11. }
    12.  
    13. Account::Account(const Account &account) {
    14. provider = account.provider;
    15. type = account.type;
    16. icon = account.icon;
    17. }
    18.  
    19. Account::~ Account() {
    20. // do nothing
    21. }
    22.  
    23. void Account::setProvider(QString _provider) {
    24. provider = _provider;
    25. }
    26.  
    27. QString Account::getProvider() {
    28. return provider;
    29. }
    30.  
    31. void Account::setType(QString _type) {
    32. type = _type;
    33. }
    34.  
    35. QString Account::getType() {
    36. return type;
    37. }
    38.  
    39. void Account::setIcon(QPixmap _icon) {
    40. icon = _icon;
    41. }
    42.  
    43. QPixmap Account::getIcon() {
    44. return icon;
    45. }
    46.  
    47. Q_DECLARE_METATYPE(Account)
    To copy to clipboard, switch view to plain text mode 

    And the error is:

    Qt Code:
    1. Account.cpp:47: error: expected constructor, destructor, or type conversion at end of input
    To copy to clipboard, switch view to plain text mode 

    The error is just at the line that invokes the macro.

    Any help is appreciated !

    Thanks,

    Rafael
    Last edited by rcintra; 14th May 2007 at 22:13.

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

    Default Re: Registering classe in QMetaType

    Place the macro in the header file not in implementation.

  3. #3
    Join Date
    Apr 2007
    Location
    Brazil
    Posts
    8
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Registering classe in QMetaType

    Hi wysota,

    Thanks for your reply.

    Actually I have already tried it, but the error seems to be the similar:

    Qt Code:
    1. #ifndef ACCOUNT_H
    2. #define ACCOUNT_H
    3.  
    4. #include <QPixmap>
    5. #include <QString>
    6.  
    7.  
    8. class Account {
    9. private:
    10. QString provider;
    11. QString type;
    12. QPixmap icon;
    13.  
    14. public:
    15. Account(QString _provider, QString type, QPixmap icon);
    16. Account();
    17. Account(const Account &account);
    18. ~Account();
    19. void setProvider(QString _provider);
    20. QString getProvider();
    21. void setType(QString _type);
    22. QString getType();
    23. void setIcon(QPixmap _icon);
    24. QPixmap getIcon();
    25. };
    26.  
    27. Q_DECLARE_METATYPE(Account)
    28.  
    29. #endif // ACCOUNT_H
    To copy to clipboard, switch view to plain text mode 

    And the error is:

    Account.cpp:3: error: expected constructor, destructor, or type conversion before ‘Account’

    Any idea?

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

    Default Re: Registering classe in QMetaType

    Ok, but this doesn't reffer to this file. What does Account.cpp:3 contain? Does Account.h include <QMetaType> anywhere?
    Last edited by wysota; 14th May 2007 at 23:10.

  5. The following user says thank you to wysota for this useful post:

    rcintra (15th May 2007)

  6. #5
    Join Date
    Apr 2007
    Location
    Brazil
    Posts
    8
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Registering classes in QMetaType

    It was missing the include <QMetaType> indeed.

    Thanks a lot, wysota !

    P.S. The error description could be just a little more specific...

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

    Default Re: Registering classes in QMetaType

    It's very specific. Remember that it's the compiler that generates it, not Qt. So it can't know you're using an identifier that's defined in QMetaType

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.