View Full Version : Problem when adding XML support
Shawn
22nd May 2007, 01:46
I want to add XML support to my project. I write like this:
in "paser.h"
#ifndef PASER_H
#define PASER_H
#include <QXmlDefaultHandler>
class paser : public QXmlDefaultHandler
{
Q_OBJECT
public:
paser(QObject *parent);
~paser();
private:
};
#endif // PASER_H
in "paser.cpp"
#include "paser.h"
paser::paser(QObject *parent)
: QXmlDefaultHandler(parent)
{
}
paser::~paser()
{
}
:crying: then the orror occurs:
error C2664: 'QXmlDefaultHandler::QXmlDefaultHandler(const QXmlDefaultHandler &)' : cannot convert parameter 1 from 'QObject *' to 'const QXmlDefaultHandler &'
Reason: cannot convert from 'QObject *' to 'const QXmlDefaultHandler'
marcel
22nd May 2007, 05:47
QXmlDefaultHandler does not have any constructor that takes a QObject* as parameter.
It has a copy constructor.
Anyway, this class is not a subclass of QObject, so you shouldn't do any parenting.
If you really need it, add a QObject* member to your class, and store the parent in this member.
Do this:
paser::paser(QObject *parent)
: QXmlDefaultHandler()
and it will work.
Regards
Shawn
22nd May 2007, 12:19
Marcel:
I did it like u suggested above.
But still error occurs:
>moc_paser.cpp
1>.\GeneratedFiles\Debug\moc_paser.cpp(37) : error C2039: 'staticMetaObject' : is not a member of 'QXmlDefaultHandler'
1> c:\qt\4.2.3\include\qtxml\qxml.h(351) : see declaration of 'QXmlDefaultHandler'
1>.\GeneratedFiles\Debug\moc_paser.cpp(51) : error C2039: 'qt_metacast' : is not a member of 'QXmlDefaultHandler'
1> c:\qt\4.2.3\include\qtxml\qxml.h(351) : see declaration of 'QXmlDefaultHandler'
1>.\GeneratedFiles\Debug\moc_paser.cpp(56) : error C2039: 'qt_metacall' : is not a member of 'QXmlDefaultHandler'
1> c:\qt\4.2.3\include\qtxml\qxml.h(351) : see declaration of 'QXmlDefaultHandler'
wysota
22nd May 2007, 12:25
Remove the Q_OBJECT macro. The handler is not a QObject! Don't treat it like one.
Shawn
22nd May 2007, 12:31
wysota
Thanks a lot!
but when I write like this in paser.cpp
public:
Paser(QObject *parent);
~Paser();
bool startElement(const QString &namespaceURI,
const QString &localName,
const QString &qName,
const QXmlAttributes &attributes);
errors again:
paser.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall Paser::startElement(class QString const &,class QString const &,class QString const &,class QXmlAttributes const &)" (?startElement@Paser@@UAE_NABVQString@@00ABVQXmlAt tributes@@@Z)
Shawn
22nd May 2007, 13:03
I got two classes: one inherited from QXmlDefaultHandler, the other from QMainWindow, like this:
class Paser : public QXmlDefaultHandler{....}
class SLD : public QMainWindow{....}
while class SLD is in charge of drawing image at given position (x,y,w,h);
class Paser is in charge of XML pasering using SAX, and I want it can emit signals if certain tags appear.
How I supposed to do this?
Thank u very much for helping!
wysota
22nd May 2007, 13:07
Did you implement that method?
Shawn
22nd May 2007, 13:16
Yes, I finally found the Qt4 Class Chart, then I noticed that it's not a QObject.
wysota
22nd May 2007, 13:20
I'm asking about startElement()
Shawn
22nd May 2007, 13:27
Ahh, Thank you very much
After implement startElement(), I succeed!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.