PDA

View Full Version : error using Q_OBJECT



Ossi
23rd September 2009, 13:41
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:


debug/moc_xmlread.cpp:39: error: ‘staticMetaObject’ is not a member of ‘QXmlDefaultHandler’
debug/moc_xmlread.cpp: In member function ‘virtual void* XmlRead::qt_metacast(const char*)’:
debug/moc_xmlread.cpp:53: error: ‘qt_metacast’ is not a member of ‘QXmlDefaultHandler’
debug/moc_xmlread.cpp: In member function ‘virtual int XmlRead::qt_metacall(QMetaObject::Call, int, void**)’:
debug/moc_xmlread.cpp:58: error: ‘qt_metacall’ is not a member of ‘QXmlDefaultHandler’



My header file:


class XmlRead : public QXmlDefaultHandler
{
Q_OBJECT

public:
XmlRead(std::map<QDate, std::vector<double> > &myMap, std::vector<QString> &profile);

bool startElement(const QString &namespaceURI,
const QString &localName,
const QString &qName,
const QXmlAttributes &attribs);
bool endElement(const QString &namespaceURI,
const QString &loacalName,
const QString &qName);
bool characters(const QString &str);
bool fatalError(const QXmlParseException &exception);

private:
std::map<QDate, std::vector<double> > *mapPtr;
std::vector<QString> *profilePtr;
QString currentText;
std::vector<double> vec;
bool validDate;
QDate myDate;
};

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

scascio
23rd September 2009, 15:48
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.

Lykurg
23rd September 2009, 15:51
use
#include <QObject> instead of the macro.

Ossi
23rd September 2009, 16:16
Thanks guys, I included QObject and used QObject::tr and it works