Results 1 to 4 of 4

Thread: error using Q_OBJECT

  1. #1
    Join Date
    Aug 2007
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default error using Q_OBJECT

    Hi all.

    I have to use the tr() function so i include the Q_OBJECT macro in my class declaration. But when I compile I get the errors:

    Qt Code:
    1. debug/moc_xmlread.cpp:39: error: ‘staticMetaObject’ is not a member of ‘QXmlDefaultHandler’
    2. debug/moc_xmlread.cpp: In member function ‘virtual void* XmlRead::qt_metacast(const char*)’:
    3. debug/moc_xmlread.cpp:53: error: ‘qt_metacast’ is not a member of ‘QXmlDefaultHandler’
    4. debug/moc_xmlread.cpp: In member function ‘virtual int XmlRead::qt_metacall(QMetaObject::Call, int, void**)’:
    5. debug/moc_xmlread.cpp:58: error: ‘qt_metacall’ is not a member of ‘QXmlDefaultHandler’
    To copy to clipboard, switch view to plain text mode 



    My header file:

    Qt Code:
    1. class XmlRead : public QXmlDefaultHandler
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. XmlRead(std::map<QDate, std::vector<double> > &myMap, std::vector<QString> &profile);
    7.  
    8. bool startElement(const QString &namespaceURI,
    9. const QString &localName,
    10. const QString &qName,
    11. const QXmlAttributes &attribs);
    12. bool endElement(const QString &namespaceURI,
    13. const QString &loacalName,
    14. const QString &qName);
    15. bool characters(const QString &str);
    16. bool fatalError(const QXmlParseException &exception);
    17.  
    18. private:
    19. std::map<QDate, std::vector<double> > *mapPtr;
    20. std::vector<QString> *profilePtr;
    21. QString currentText;
    22. std::vector<double> vec;
    23. bool validDate;
    24. QDate myDate;
    25. };
    To copy to clipboard, switch view to plain text mode 

    If I remove the Q_OBJECT macro the compiler cant find the tr() function... What am I doing wrong?

  2. #2
    Join Date
    Sep 2009
    Posts
    140
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    4
    Thanked 17 Times in 17 Posts

    Default Re: error using Q_OBJECT

    the Q_OBJECT macro is reserved for derived class of QObject.
    Are your sur it is the case of QXmlDefaultHandler?

    You can use QObject::tr() without derivation, since it is a static method.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: error using Q_OBJECT

    use
    Qt Code:
    1. #include <QObject>
    To copy to clipboard, switch view to plain text mode 
    instead of the macro.

  4. #4
    Join Date
    Aug 2007
    Posts
    11
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

    Default Re: error using Q_OBJECT

    Thanks guys, I included QObject and used QObject::tr and it works

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.