Results 1 to 10 of 10

Thread: Problem when adding XML support

  1. #1
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Problem when adding XML support

    I want to add XML support to my project. I write like this:

    in "paser.h"
    Qt Code:
    1. #ifndef PASER_H
    2. #define PASER_H
    3. #include <QXmlDefaultHandler>
    4.  
    5. class paser : public QXmlDefaultHandler
    6. {
    7. Q_OBJECT
    8.  
    9. public:
    10. paser(QObject *parent);
    11. ~paser();
    12.  
    13. private:
    14.  
    15. };
    16.  
    17. #endif // PASER_H
    To copy to clipboard, switch view to plain text mode 

    in "paser.cpp"
    Qt Code:
    1. #include "paser.h"
    2.  
    3. paser::paser(QObject *parent)
    4. {
    5.  
    6. }
    7.  
    8. paser::~paser()
    9. {
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    then the orror occurs:
    Qt Code:
    1. error C2664: 'QXmlDefaultHandler::QXmlDefaultHandler(const QXmlDefaultHandler &)' : cannot convert parameter 1 from 'QObject *' to 'const QXmlDefaultHandler &'
    2. Reason: cannot convert from 'QObject *' to 'const QXmlDefaultHandler'
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem when adding XML support

    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:
    Qt Code:
    1. paser::paser(QObject *parent)
    To copy to clipboard, switch view to plain text mode 
    and it will work.

    Regards

  3. #3
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem when adding XML support

    Marcel:
    I did it like u suggested above.
    But still error occurs:
    Qt Code:
    1. >moc_paser.cpp
    2. 1>.\GeneratedFiles\Debug\moc_paser.cpp(37) : error C2039: 'staticMetaObject' : is not a member of 'QXmlDefaultHandler'
    3. 1> c:\qt\4.2.3\include\qtxml\qxml.h(351) : see declaration of 'QXmlDefaultHandler'
    4. 1>.\GeneratedFiles\Debug\moc_paser.cpp(51) : error C2039: 'qt_metacast' : is not a member of 'QXmlDefaultHandler'
    5. 1> c:\qt\4.2.3\include\qtxml\qxml.h(351) : see declaration of 'QXmlDefaultHandler'
    6. 1>.\GeneratedFiles\Debug\moc_paser.cpp(56) : error C2039: 'qt_metacall' : is not a member of 'QXmlDefaultHandler'
    7. 1> c:\qt\4.2.3\include\qtxml\qxml.h(351) : see declaration of 'QXmlDefaultHandler'
    To copy to clipboard, switch view to plain text mode 

  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: Problem when adding XML support

    Remove the Q_OBJECT macro. The handler is not a QObject! Don't treat it like one.

  5. #5
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem when adding XML support

    wysota
    Thanks a lot!
    but when I write like this in paser.cpp
    Qt Code:
    1. public:
    2. Paser(QObject *parent);
    3. ~Paser();
    4. bool startElement(const QString &namespaceURI,
    5. const QString &localName,
    6. const QString &qName,
    7. const QXmlAttributes &attributes);
    To copy to clipboard, switch view to plain text mode 
    errors again:
    Qt Code:
    1. 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@@00ABVQXmlAttributes@@@Z)
    To copy to clipboard, switch view to plain text mode 
    Last edited by Shawn; 22nd May 2007 at 12:54.

  6. #6
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem when adding XML support

    I got two classes: one inherited from QXmlDefaultHandler, the other from QMainWindow, like this:
    Qt Code:
    1. class Paser : public QXmlDefaultHandler{....}
    2. class SLD : public QMainWindow{....}
    To copy to clipboard, switch view to plain text mode 

    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!

  7. #7
    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: Problem when adding XML support

    Did you implement that method?

  8. #8
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem when adding XML support

    Yes, I finally found the Qt4 Class Chart, then I noticed that it's not a QObject.

  9. #9
    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: Problem when adding XML support

    I'm asking about startElement()

  10. #10
    Join Date
    May 2007
    Posts
    91
    Thanks
    60
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem when adding XML support

    Ahh, Thank you very much
    After implement startElement(), I succeed!

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.