Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to download xml file and parse it using qt.
Forum Updated to NodeBB v4.3 + New Features

How to download xml file and parse it using qt.

Scheduled Pinned Locked Moved General and Desktop
15 Posts 6 Posters 10.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sierdzioS Offline
    sierdzioS Offline
    sierdzio
    Moderators
    wrote on last edited by
    #6

    First, wrap your code in '@' tags. Now, on with the problems:

    1. You are using QObject::connect() from which I gather, that your class is not QObject-derivative. In order to connect with fileReplyParsed(), you have to declare it a slot in your header file.
    2. More importantly, I see no reference to any class in your .cpp, yet you are using 'this' pointer... something is definitely missing in the code snippet you provided :)
    3. As for the last error - you should definitely avoid the standard constructor for QUrl - in Qt4, it does not work properly (it is fixed in Qt5), use one of the static methods instead (like QUrl::fromUserInput() etc.).

    (Z(:^

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #7

      To use signals and slots your class has to be a (direct or indirect) subclass of QObject and it has to mention Q_OBJECT at the top of its declaration. In addition you are missing an include for QNetworkRequest.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mady
        wrote on last edited by
        #8

        Thanks for such a super fast reply.....:)

        1.> Yes, these functions are belong to "class my_class". Are you suggesting to derive my_calss from QObject?
        It seems we can't derive QObject in to my class. got few other build erros.

        builf error:

        c:\my code\qtxml_parsing\qtxml_parsing\qtxml_parsing.cpp(89) : error C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'

        2.> You asked to declear a slot in header file, I have defined it in .cpp file "fileReplyFinished". Was that not enough?

        1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #9

          [quote author="mady" date="1318486806"]Thanks for such a super fast reply.....:)

          1.> Yes, these functions are belong to "class my_class". Are you suggesting to derive my_calss from QObject?
          It seems we can't derive QObject in to my class. got few other build erros.

          builf error:

          c:\my code\qtxml_parsing\qtxml_parsing\qtxml_parsing.cpp(89) : error C2248: 'QObject::QObject' : cannot access private member declared in class 'QObject'

          2.> You asked to declear a slot in header file, I have defined it in .cpp file "fileReplyFinished". Was that not enough?
          [/quote]

          Here are some basic details about signal-slot system: http://doc.qt.nokia.com/latest/signalsandslots.html#signals-and-slots

          It provides some small examples on how to declare everything and how does it work. Should solve most of your problems here. You can also take look into QWebService I've linked earlier, but it is somewhat more complicated, so might not be good for learning.

          To put it shortly:

          1. You've got to declare fileReplyFinished() as slot in header file, for example:
            @ protected slots:
            void fileReplyFinished(QNetworkReply *r);
            @

          2. Then in .cpp, remember to use the class prefix:
            @
            void my_class::fileReplyFinished(QNetworkReply *reply) {
            // ...
            }
            @

          3. In my_func(), you can use plain connect(), instead of QObject::connect() now that your class has the Q_OBJECT macro.

          (Z(:^

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mady
            wrote on last edited by
            #10

            Thanks a lot......
            I am able to resolve that build error with your help. but now getting some wiered linking errors.... Seems l have to include some library for network programing. Please let me know if it is so. I am pasting linking errors those I am getting.

            QTXML_parsing.obj : error LNK2019: unresolved external symbol "public: __thiscall QNetworkRequest::~QNetworkRequest(void)" (??1QNetworkRequest@@QAE@XZ) referenced in function "public: void __thiscall Updater::GetLatestVersion(void)" (?GetLatestVersion@Updater@@QAEXXZ)
            1>QTXML_parsing.obj : error LNK2019: unresolved external symbol "public: class QNetworkReply * __thiscall QNetworkAccessManager::get(class QNetworkRequest const &)" (?get@QNetworkAccessManager@@QAEPAVQNetworkReply@@ABVQNetworkRequest@@@Z) referenced in function "public: void __thiscall Updater::GetLatestVersion(void)" (?GetLatestVersion@Updater@@QAEXXZ)
            1>QTXML_parsing.obj : error LNK2019: unresolved external symbol "public: __thiscall QNetworkRequest::QNetworkRequest(class QUrl const &)" (??0QNetworkRequest@@QAE@ABVQUrl@@@Z) referenced in function "public: void __thiscall Updater::GetLatestVersion(void)" (?GetLatestVersion@Updater@@QAEXXZ)
            1>QTXML_parsing.obj : error LNK2019: unresolved external symbol "public: static class QUrl __cdecl QUrl::fromUserInput(class QString const &)" (?fromUserInput@QUrl@@SA?AV1@ABVQString@@@Z) referenced in function "public: void __thiscall Updater::GetLatestVersion(void)" (?GetLatestVersion@Updater@@QAEXXZ)
            1>QTXML_parsing.obj : error LNK2019: unresolved external symbol "char const * __cdecl qFlagLocation(char const *)" (?qFlagLocation@@YAPBDPBD@Z) referenced in function "public: void __thiscall Updater::GetLatestVersion(void)" (?GetLatestVersion@Updater@@QAEXXZ)
            1>QTXML_parsing.obj : error LNK2019: unresolved external symbol "public: __thiscall QNetworkAccessManager::QNetworkAccessManager(class QObject *)" (??0QNetworkAccessManager@@QAE@PAVQObject@@@Z) referenced in function "public: void __thiscall Updater::GetLatestVersion(void)" (?GetLatestVersion@Updater@@QAEXXZ)
            1>QTXML_parsing.obj : error LNK2001: unresolved external symbol "private: static class QCoreApplication * QCoreApplication::self" (?self@QCoreApplication@@0PAV1@A)
            1>QTXML_parsing.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Updater::metaObject(void)const " (?metaObject@Updater@@UBEPBUQMetaObject@@XZ)
            1>QTXML_parsing.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall Updater::qt_metacast(char const *)" (?qt_metacast@Updater@@UAEPAXPBD@Z)
            1>QTXML_parsing.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall Updater::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Updater@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
            1>QTXML_parsing.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Counter::metaObject(void)const " (?metaObject@Counter@@UBEPBUQMetaObject@@XZ)
            1>QTXML_parsing.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall Counter::qt_metacast(char const *)" (?qt_metacast@Counter@@UAEPAXPBD@Z)
            1>QTXML_parsing.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall Counter::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Counter@@UAEHW4Call@QMetaObject@@HPAPAX@Z)

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #11

              It seems that you lack

              @
              QT += network
              @

              in your .pro file.

              [EDIT: it's QT not CONFIG]

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mady
                wrote on last edited by
                #12

                Thanks for response.
                Now I am facing one new interesting linker error, BTW, I am using VS2008 + QT libraries for my tasks.

                When I am adding Q_OBJECT in my_class (since my class has slots) I am getting below linker error.

                1>QTXML_parsing.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Updater::metaObject(void)const " (?metaObject@Updater@@UBEPBUQMetaObject@@XZ)
                1>QTXML_parsing.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall Updater::qt_metacast(char const *)" (?qt_metacast@Updater@@UAEPAXPBD@Z)
                1>QTXML_parsing.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall Updater::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@Updater@@UAEHW4Call@QMetaObject@@HPAPAX@Z)

                But If I remove Q_OBJECT I am not getting any linker error but my program is throwing an exception as below

                Object::connect: No such slot QObject::fileReplyFinished(QNetworkReply*) in c:\my code\qtxml_parsing\qtxml_parsing\qtxml_parsing.cpp:106
                QEventLoop: Cannot be used without QApplication
                QObject::connect: Cannot connect (null)::aboutToQuit() to QNativeWifiEngine::clo
                seHandle()

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  KA51O
                  wrote on last edited by
                  #13

                  you have to moc the header file.

                  1.) Add this to your custom build step settings:

                  Command line: moc -o .\$(IntDir)\moc_$(InputName).cpp $(InputPath)
                  
                  Outputs: .\$(IntDir)\moc_$(InputName).cpp
                  

                  2.) Compile the header file

                  3.) Include the generated moc file in your project.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    goetz
                    wrote on last edited by
                    #14

                    It's usually sufficient (and needed) to re-run qmake and sometimes to do a rebuild of your project. Including the moc file into the project is not needed for qmake based projects, as this is handled by qmake automatically. qmake sometimes doesn't catch up .pro file changes and does not regenerate the Makefile automatically.

                    http://www.catb.org/~esr/faqs/smart-questions.html

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      KA51O
                      wrote on last edited by
                      #15

                      I wasn't sure if he is using qmake (he just mentioned VS2008). It would of course be the best way to go.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved