Results 1 to 4 of 4

Thread: Q_PROPERTY: the example doesn't work!

  1. #1
    Join Date
    Nov 2008
    Posts
    27
    Qt products
    Qt4
    Platforms
    Windows

    Default Q_PROPERTY: the example doesn't work!

    I am trying to build the example from documentation, but it fails:
    Qt Code:
    1. #include <QtCore>
    2.  
    3. #include <iostream>
    4. using namespace std;
    5.  
    6. class MyClass : public QObject
    7. {
    8. Q_OBJECT
    9. Q_PROPERTY(Priority priority READ priority WRITE setPriority)
    10. Q_ENUMS(Priority)
    11.  
    12. public:
    13. MyClass(QObject *parent = 0)
    14. :QObject(parent)
    15. {
    16.  
    17. };
    18. ~MyClass()
    19. {
    20. cout << "MyClass Destructor"<<endl;
    21. };
    22.  
    23. enum Priority { High, Low, VeryHigh, VeryLow };
    24.  
    25. void setPriority(Priority priority);
    26. Priority priority() const;
    27. };
    28.  
    29.  
    30. int main(int argc, char *argv[])
    31. {
    32. QCoreApplication a(argc, argv);
    33. MyClass megaInst;
    34. return a.exec();
    35. }
    To copy to clipboard, switch view to plain text mode 

    My VS writes me:
    1>main.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall MyClass::metaObject(void)const " (?metaObject@MyClass@@UBEPBUQMetaObject@@XZ)
    1>main.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall MyClass::qt_metacast(char const *)" (?qt_metacast@MyClass@@UAEPAXPBD@Z)
    1>main.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall MyClass::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@MyClass@@UAEHW4Call@QMetaObject@@HPA PAX@Z)
    How can it be fixed?
    Last edited by jpn; 7th July 2009 at 08:41. Reason: missing [code] tags

  2. #2
    Join Date
    Sep 2008
    Posts
    25
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Q_PROPERTY: the example doesn't work!

    Hi!

    Exactly, it's just an example, to give you an idea to how it might work.
    To make this code compile, put the class in a header file and provide definition for the setPriority and priority functions.
    It's not required but it's a good practice to separate declaration from definition, to put the class definition in a separate source file

  3. #3
    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: Q_PROPERTY: the example doesn't work!

    If you're using QMake then place a "#include main.moc" entry just before the main function, rerun qmake and recompile. By default qmake only scans header files for Q_OBJECT macros.
    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
    Join Date
    Jan 2009
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Question Re: Q_PROPERTY: the example doesn't work!

    Hello All,

    Could anybody answer me also. Is the Q_PARAMETER the way to do the following:
    Qt Code:
    1. megaInst.priority = MyClass::VeryHigh;
    To copy to clipboard, switch view to plain text mode 
    or it always have to be
    Qt Code:
    1. megaInst.setPriority(MyClass::VeryHigh);
    To copy to clipboard, switch view to plain text mode 
    (I mean a variable imitation but not function call). If not, what a purpose of Q_PROPERTY if you have to reach property as function?

    Or is there any other way to do that?

    Thanks

Similar Threads

  1. getting MySQL to work with Qt
    By Ashish in forum Installation and Deployment
    Replies: 7
    Last Post: 19th May 2009, 08:57
  2. Qt4 : QPainter::setRedirected doesn't work
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2008, 17:52
  3. QActions don't work with menubar hidden
    By Pepe in forum Qt Programming
    Replies: 1
    Last Post: 16th August 2007, 01:04
  4. Change work area OS
    By pakulo in forum Qt Programming
    Replies: 15
    Last Post: 15th May 2007, 07:20

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.