You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Sunday, February 26th 2012, 7:30pm

QXmlReader producing errors

Hello,
I just registered because I have a strange problem with the QXmlReader and I really need quick help there.
So I've written a program which reads in a XML, that works to some point, there are a few lines which don't get read properly.

Source code

1
2
3
4
5
6
7
<value key="fMeshLODLevel2FadeDist">10000000.0000</value>
<value key="fMeshLODLevel1FadeDist">10000000.0000</value>
<value key="sD3DDevice">&quot;ATI Radeon HD 5800 Series&quot;</value>

<value key="SGeneralMasterMismatchWarning">One or more plugins could not find the correct versions of the master files they depend on. Errors may occur during load or game play. Check the &quot;Warnings.txt&quot; file for more information.</value>
<value key="sResourceArchiveList">Skyrim - Misc.bsa, Skyrim - Shaders.bsa, Skyrim - Textures.bsa, HighResTexturePack01.bsa, HighResTexturePack02.bsa, Skyrim - Interface.bsa, Skyrim - Animations.bsa, Skyrim - Meshes.bsa, Skyrim - Sounds.bsa </value>
<value key="sResourceArchiveList2">Skyrim - Voices.bsa, Skyrim - VoicesExtra.bsa</value>


for some reason those line produce this:

Source code

1
2
3
4
5
6
7
0<NULL>eshLODLevel2FadeDist: 10000000.0000
0<NULL>eshLODLevel1FadeDist: 10000000.0000
HD 5800 Se: "ATI Radeon HD 5800 Series"

plugins could not find the co: One or more plugins could not find the correct versions of the master files they depend on. Errors may occur during load or game play. Check the "Warnings.txt" file for more information.
c.bsa, Skyrim - Shad: Skyrim - Misc.bsa, Skyrim - Shaders.bsa, Skyrim - Textures.bsa, HighResTexturePack01.bsa, HighResTexturePack02.bsa, Skyrim - Interface.bsa, Skyrim - Animations.bsa, Skyrim - Meshes.bsa, Skyrim - Sounds.bsa 
ces.bsa, Skyrim - Voi: Skyrim - Voices.bsa, Skyrim - VoicesExtra.bsa

(Note: the <NULL> just represents the 0-byte)

So what could be the reason for this data corruption?
Every other line in the file works flawlessly, just those don't.

Thanks in advance!

EDIT:
I think it wouldn't be a bad idea to post the code:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
    QStringRef key;

    QFile *pFile = new QFile(file.selectedFiles().at(0));
    pFile->open(QIODevice::ReadOnly | QIODevice::Text);
    QXmlStreamReader *pReader = new QXmlStreamReader(pFile);

    QMessageBox msg;

    while(pReader->readNextStartElement())
    {
        if(pReader->name() == "cfg")
        {
            if(pReader->attributes().value("ver") == "1.0")
            {
                continue;
            }
            else
            {
                break;
            }
        }
        else if(pReader->name() == "config")
        {
            if(pReader->attributes().value("file") == "user")
            {
                //do something

            }
            else if(pReader->attributes().value("file") == "main")
            {
                //do something
            }

            while(pReader->readNextStartElement())
            {
                if(pReader->name() == "section")
                {
                    conf->startSection(pReader->attributes().value("name").toString());

                    while(pReader->readNextStartElement())
                    {
                        if(pReader->name() == "value")
                        {
                            if((key = pReader->attributes().value("key")).isEmpty())
                                continue;

                            msg.setText("Key: "+key.toString()+" Value: "+pReader->readElementText());
                            msg.exec();
                            conf->setValue(key.toString(), pReader->readElementText(), uFile);
                        }
                        else pReader->skipCurrentElement();
                    }

                    conf->endSection();
                }
                else pReader->skipCurrentElement();
            }
        }
        else pReader->skipCurrentElement();
    }

    pReader->clear();
    pFile->close();

This post has been edited 1 times, last edit by "pfannkuchen_gesicht" (Feb 26th 2012, 7:36pm)


2

Sunday, February 26th 2012, 8:35pm

have you debugged your program to see why/where the values come from?

what you have posted is not complete and nobody else can check it...
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

3

Sunday, February 26th 2012, 8:39pm

uhm, well the relevant part of the function is there, you can ignore the "conf->" stuff, this isn't producing these errors.
So quickly opening a new project and inserting that and opening a random xml file with the structure like shown below should work.
The File looks like this:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?xml version="1.0" encoding="UTF-8"?>
<cfg ver="1.0">
    <config file="main">
        <section name="General">
            <value key="fBrightLightColorB">1.0000</value>
            <value key="fBrightLightColorG">1.0000</value>
            <value key="fBrightLightColorR">1.0000</value>
            <value key="iStoryManagerLoggingEvent">-1</value>
            <value key="bEnableStoryManagerLogging">0</value>
            <value key="fDefaultFOV">85</value>
            <value key="bUseThreadedMorpher">0</value>
            <value key="bUseThreadedMeshes">0</value>
            <value key="bUseThreadedTextures">1</value>
            <value key="bUseThreadedBlood">1</value>
            <value key="bUseThreadedParticleSystem">1</value>
            <value key="bUseThreadedLOD">1</value>
        </section>
        <section name="Imagespace">
            <value key="bDoDepthOfField">1</value>
            <value key="iRadialBlurLevel">2</value>
        </section>
        <section name="Display">
            <value key="iBlurDeferredShadowMask">1</value>
            <value key="fInteriorShadowDistance">2000</value>
            <value key="fShadowDistance">4000</value>
            <value key="iShadowMapResolutionSecondary">4096</value>
            <value key="iShadowMapResolutionPrimary">4096</value>
            <value key="iShadowSplitCount">2</value>
            <value key="iMaxAnisotropy">16</value>
            <value key="fLeafAnimDampenDistEnd">4600.0000</value>
            <value key="fLeafAnimDampenDistStart">3600.0000</value>
            <value key="fTreesMidLODSwitchDist">5000</value>
            <value key="fGamma">1</value>
            <value key="fDecalLOD2">1500</value>
            <value key="fDecalLOD1">1000</value>
            <value key="fSpecularLODStartFade">1000</value>
            <value key="fShadowLODStartFade">200</value>
            <value key="fLightLODStartFade">2500</value>
            <value key="iTexMipMapMinimum">0</value>
            <value key="iTexMipMapSkip">0</value>
            <value key="iWaterMultiSamples">0</value>
            <value key="iMultiSample">4</value>
            <value key="iShadowMode">3</value>
            <value key="bTreesReceiveShadows">1</value>
            <value key="bDrawLandShadows">1</value>
            <value key="bFull Screen">1</value>
            <value key="iSize H">1080</value>
            <value key="iSize W">1920</value>
            <value key="fMeshLODFadePercentDefault">1.2000</value>
            <value key="fMeshLODFadeBoundDefault">256.0000</value>
            <value key="fMeshLODLevel2FadeTreeDistance">7500</value>
            <value key="fMeshLODLevel1FadeTreeDistance">10000</value>
            <value key="fMeshLODLevel2FadeDist">10000000.0000</value>
            <value key="fMeshLODLevel1FadeDist">10000000.0000</value>
            <value key="iScreenShotIndex">117</value>
            <value key="bShadowMaskZPrepass">0</value>
            <value key="bMainZPrepass">0</value>
            <value key="iMaxSkinDecalsPerFrame">10</value>
            <value key="iMaxDecalsPerFrame">30</value>
            <value key="bFloatPointRenderTarget">0</value>
            <value key="sD3DDevice">&quot;ATI Radeon HD 5800 Series&quot;</value>
            <value key="bFXAAEnabled">0</value>
            <value key="iShadowMapResolution">4096</value>
            <value key="fShadowBiasScale">0.5</value>
            <value key="iShadowMaskQuarter">8</value>
            <value key="iAdapter">0</value>
            <value key="iPresentInterval">0</value>
            <value key="bTransparencyMultisampling">1</value>
            <value key="bDrawShadows">1</value>
            <value key="iShadowFilter">1</value>
            <value key="bActorSelfShadowing">1</value>
            <value key="bUseSunbeams">1</value>
            <value key="bSimpleLighting">0</value>
            <value key="bEquippedTorchesCastShadows">1</value>
        </section>
    </config>
</cfg>

4

Sunday, February 26th 2012, 9:06pm

And what did you find when you used your debugger? It will be more useful for you to debug it yourself.

Also, your code is still not compilable.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

5

Sunday, February 26th 2012, 9:22pm

it should be, you just have to use a file instead of "file." or you add a file dialogue.
I'm using Qt Creator and the MSVC++ 08 compiler and for some reason I don't get the debugger installed, but my guess is, that the xml reader has problems with too long text strings.

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
void MainWindow::configImport()
{
    QStringRef key;

    QFile *pFile = new QFile("./test.xml");
    pFile->open(QIODevice::ReadOnly | QIODevice::Text);
    QXmlStreamReader *pReader = new QXmlStreamReader(pFile);

    QMessageBox msg;

    while(pReader->readNextStartElement())
    {
        if(pReader->name() == "cfg")
        {
            if(pReader->attributes().value("ver") == "1.0")
            {
                continue;
            }
            else
            {
                break;
            }
        }
        else if(pReader->name() == "config")
        {
            while(pReader->readNextStartElement())
            {
                if(pReader->name() == "section")
                {
                    while(pReader->readNextStartElement())
                    {
                        if(pReader->name() == "value")
                        {
                            if((key = pReader->attributes().value("key")).isEmpty())
                                continue;

                            msg.setText("Key: "+key.toString()+" Value: "+pReader->readElementText());
                            msg.exec();
                        }
                        else pReader->skipCurrentElement();
                    }
                }
                else pReader->skipCurrentElement();
            }
        }
        else pReader->skipCurrentElement();
    }

    pReader->clear();
    pFile->close();
}


so here is the code again, this time without the "file".
It compiles perfectly fine for me, but still the same error.

This post has been edited 1 times, last edit by "pfannkuchen_gesicht" (Feb 26th 2012, 9:30pm)


6

Sunday, February 26th 2012, 9:52pm

Sigh. No, if I use that code it will not compile. Is everyone meant to guess all of the code that is MISSING?

If you want to use qt creator and msvc debugger then you can't use the only installed debugger (gdb or something). You need to look at debug tool sfor windows.
http://doc.qt.nokia.com/qtcreator-snapsh…er-engines.html
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

7

Sunday, February 26th 2012, 10:10pm

I just made a new project and inserted this exact function into my MainWindow class, the same class which is automaticly created when you create a new project in qt creator.
There is nothing missing at all, just the base template delivered in every complete qt package, so why should I post code which everyone has locally anyways?
Of course you have to add the includes, which shouldn't be much of a problem.

So anyways, if you're not willing to let Qt create you the template then I post it:

mainwindow.cpp:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <QFile>
#include <QXmlStreamReader>
#include <QString>
#include <QTreeWidgetItem>
#include <QMessageBox>
#include <QList>
#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    configImport();
}

void MainWindow::configImport()
{
    QStringRef key;

    QFile *pFile = new QFile("./test.xml");
    pFile->open(QIODevice::ReadOnly | QIODevice::Text);
    QXmlStreamReader *pReader = new QXmlStreamReader(pFile);

    QMessageBox msg;

    while(pReader->readNextStartElement())
    {
        if(pReader->name() == "cfg")
        {
            if(pReader->attributes().value("ver") == "1.0")
            {
                continue;
            }
            else
            {
                break;
            }
        }
        else if(pReader->name() == "config")
        {
            while(pReader->readNextStartElement())
            {
                if(pReader->name() == "section")
                {
                    while(pReader->readNextStartElement())
                    {
                        if(pReader->name() == "value")
                        {
                            if((key = pReader->attributes().value("key")).isEmpty())
                                continue;

                            msg.setText("Key: "+key.toString()+" Value: "+pReader->readElementText());
                            msg.exec();
                        }
                        else pReader->skipCurrentElement();
                    }
                }
                else pReader->skipCurrentElement();
            }
        }
        else pReader->skipCurrentElement();
    }

    pReader->clear();
    pFile->close();
}

MainWindow::~MainWindow()
{
    delete ui;
}

mainwindow.h:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    void configImport();
    ~MainWindow();
    
private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

main.cpp:

Source code

1
2
3
4
5
6
7
8
9
10
11
#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    
    return a.exec();
}

xml_test.pro:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
QT       += core gui

TARGET = xml_test
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

mainwindow.ui:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralWidget">
   <widget class="QTreeWidget" name="treeWidget">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>0</y>
      <width>401</width>
      <height>192</height>
     </rect>
    </property>
    <property name="columnCount">
     <number>5</number>
    </property>
    <column>
     <property name="text">
      <string notr="true">1</string>
     </property>
    </column>
    <column>
     <property name="text">
      <string notr="true">2</string>
     </property>
    </column>
    <column>
     <property name="text">
      <string notr="true">3</string>
     </property>
    </column>
    <column>
     <property name="text">
      <string notr="true">4</string>
     </property>
    </column>
    <column>
     <property name="text">
      <string notr="true">5</string>
     </property>
    </column>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menuBar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>400</width>
     <height>21</height>
    </rect>
   </property>
  </widget>
  <widget class="QToolBar" name="mainToolBar">
   <attribute name="toolBarArea">
    <enum>TopToolBarArea</enum>
   </attribute>
   <attribute name="toolBarBreak">
    <bool>false</bool>
   </attribute>
  </widget>
  <widget class="QStatusBar" name="statusBar"/>
 </widget>
 <layoutdefault spacing="6" margin="11"/>
 <resources/>
 <connections/>
</ui>


you see, absolutely nothing to guess, just the default template with the extra function.

8

Sunday, February 26th 2012, 10:46pm

Firstly, not everyone that uses Qt also has or uses creator. So no, not everyone has this 'locally'.

Secondly, the first time you posted, you didnt even show the class or method that it was from. Then you didnt even post a header file - MainWindow could be anything. Why should the onus to discover all these things be on the people you are asking for help from? It's a pet peeve that all too frequently people hide far too much information. As you did here.

You should make things as easy as possible. Post everything that is needed for others to compile.

Moreover, you are trying to write code and you can't debug. That should be your first priority - getting your debugger working.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

This post has been edited 1 times, last edit by "Amleto" (Feb 26th 2012, 10:55pm)


9

Sunday, February 26th 2012, 11:21pm

Btw, have you read Docs for QStringRef? You are misusing it.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

10

Sunday, February 26th 2012, 11:41pm

yeah, I did, I guess I didn't read careful enough then, but I don't see what I've done wrong there.
Please explain.

11

Monday, February 27th 2012, 8:33am

Source code

1
2
3
4
 if((key = pReader->attributes().value("key")).isEmpty())
    continue;

msg.setText("Key: "+key.toString()+" Value: "+pReader->readElementText());


preader->readElementText() invalidates your stringref 'key'. You should save the value of the QStringRef to a QString before using non const member of QXmlStreamReader.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

12

Tuesday, February 28th 2012, 7:52am

ah, thanks a lot!
Totally forgot about that stuff about QStringRef.