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. [NEWBIE] Parsing XML to strings
Forum Updated to NodeBB v4.3 + New Features

[NEWBIE] Parsing XML to strings

Scheduled Pinned Locked Moved General and Desktop
20 Posts 5 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.
  • H Offline
    H Offline
    HowyHappy
    wrote on 15 Aug 2011, 19:12 last edited by
    #11

    Wow, quickly reading through the basics helped a lot. Now, I have the initial Xml parsed to strings, and I'm ready to proceed with building DOM-trees.
    ...When I learn how to build them.
    I must say: QXmlStreamReader is simple to use once you understand how it works.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on 15 Aug 2011, 19:34 last edited by
      #12

      [quote author="HowyHappy" date="1313435556"]Now, I have the initial Xml parsed to strings, and I'm ready to proceed with building DOM-trees.[/quote]

      If you're wanting a DOM tree, perhaps your best bet would be simply using "QDomDocument":http://doc.qt.nokia.com/latest/qdomdocument.html rather than building one from scratch with strings read from an QXmlStreamReader.

      But, it all depends on your use case.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        HowyHappy
        wrote on 16 Aug 2011, 00:31 last edited by
        #13

        Well, of course, I won't use QXmlStreamReader to build a DOM tree. It wouldn't be sufficient for the amounts of data this program should be able to handle. In this usecase, I want there to be indexes for different kinds of objects that can be pulled easily into a renderer and other components. So, f.ex., you'd be able to pull trees of all sorts, and it will load the different properties of it like texture and model without further fuzz.
        For this purpose, a QDomDocument will do perfectly.
        I have all the features and ways of doing it planned well. The thing missing is writing it.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on 16 Aug 2011, 16:29 last edited by
          #14

          Ok... I was just making sure you knew the options. Since you'd self-proclaimed yourself as a "newbie" then there was a little room for interpretation (and guessing) about what you knew about and what you didn't. :-)

          Good luck with your coding!

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • H Offline
            H Offline
            HowyHappy
            wrote on 16 Aug 2011, 18:25 last edited by
            #15

            I think I've made some progress, but so far I've taken it after my own perception of what does what.
            This is the code:
            @void LaunchPad::parseActors() {
            //Open the file and assign it to the document
            QFile actorFile(globalActorsFile);
            actorFile.open(QIODevice::ReadOnly | QIODevice::Text);
            actorIndex.setContent(&actorFile);

            //Start building the DOM tree
            QDomElement actorElement;
            QDomNodeList actors = actorElement.elementsByTagName("sysName");
            

            }@
            Will this build me a usable DOM tree?
            This is an example of the target document:
            @<actors>
            <actor name="hero" sysName="hero">
            <model>act_hero_001.zact</model>
            <texture>act_hero_001.ztex</texture>
            </actor>
            <actor name="Princess" sysName="princess">
            <type>NPC</type>
            <model>act_princess_001.zact</model>
            <texture>act_princess_001.ztex</texture>
            <talk>true</talk>
            <logic>act_princess.zlgc</logic>
            </actor>
            </actors>@
            Would I be able to fetch all the child nodes of the actor called "hero"?
            Or am I only halfway?

            And I'm also trying to draw a test-window, just to see that the text gets parsed. So I put in this function:
            @void LaunchPad::drawTestWindow() {
            QWidget titleWindow;
            titleWindow.setWindowTitle(gameName);
            titleWindow.show();
            }@
            But it doesn't seem to work well so far.
            I get this weird error, it says:
            @/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5.2/../../../crt1.o: In function _start': (.text+0x20): undefined reference to main'
            collect2: ld returned 1 exit status@
            I bet that I've forgotten to enter something that is required by QWidget or displaying something in general..?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mlong
              wrote on 16 Aug 2011, 18:30 last edited by
              #16

              Where is your main()? Looks like the linker can't find it.

              Software Engineer
              My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

              1 Reply Last reply
              0
              • H Offline
                H Offline
                HowyHappy
                wrote on 16 Aug 2011, 23:15 last edited by
                #17

                I'm having a problem with main()...
                I don't know how to use it.
                I've written this so far:
                @#include <QtGui/QApplication>
                #include <QWidget>

                #include "xmlinterpret.h"

                int main(int argc, char *argv[]) {
                QApplication app(argc, argv);

                return app.exec();
                

                }
                @
                But I don't understand how to make it show the widget I configured...
                I assume that I have to use a pointer somewhere?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on 16 Aug 2011, 23:17 last edited by
                  #18

                  @
                  #include <QtGui/QApplication>
                  #include "somewidget.h"

                  int main(int argc, char *argv[])
                  {
                  QApplication app(argc, argv);

                  SomeWidget sw;  
                  sw.show();
                  
                  return app.exec&#40;&#41;;
                  

                  }
                  @

                  or just look at pretty much any of the examples in the docs.

                  Software Engineer
                  My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                  1 Reply Last reply
                  0
                  • H Offline
                    H Offline
                    HowyHappy
                    wrote on 19 Aug 2011, 00:22 last edited by
                    #19

                    I've successfully implemented the int main function now. I chose to put it in the same file, because then I won't have to use pointers, and this is basicly the launchpad for the engine where it all begins.

                    Ok, new problem:
                    The program is nicely written now, but I'm not entirely sure on how to use QFile.
                    So far, I've used it this way:
                    @QFile xmlFile;
                    xmlFile.setFileName("game.xml");@
                    And:
                    @QFile actorFile(globalActorsFile);@
                    I also set QDir to the current directory in main() like so:
                    @QDir::setCurrent(".");@
                    But when I try to start the program, I get "QFSFileEngine::open: No file name specified".
                    What have I done wrong?

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      goetz
                      wrote on 22 Aug 2011, 14:47 last edited by
                      #20

                      Relative paths are resolved relative to the current directory. The dot "." represents the current directory. So our setCurrent is nothing else than "change the current directory to the current directory".

                      I guess you want to set the current directory to that folder that holds the executable. If so, then use this:

                      @
                      QDir::setCurrent(qApp->applicationDirPath());
                      @

                      Or better prepend your file path with that string.

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

                      1 Reply Last reply
                      0

                      20/20

                      22 Aug 2011, 14:47

                      • Login

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