Hi all,
I am experiencing a strange behaviour when i am trying to read an xml file.
I just want to print a message when the startofdocument is found.
the header file:
#ifndef KENTRIKO_H
#define KENTRIKO_H
#include <QtGui>
#include <QApplication>
#include <QtCore>
#include "ui_kentriko.h"
{
Q_OBJECT
public:
~kentriko();
public slots:
void anigma_arxiou();
void diabase();
private:
Ui::kentrikoClass ui;
QXmlStreamReader ena;
};
#endif // KENTRIKO_H
#ifndef KENTRIKO_H
#define KENTRIKO_H
#include <QtGui>
#include <QApplication>
#include <QtCore>
#include "ui_kentriko.h"
class kentriko : public QMainWindow
{
Q_OBJECT
public:
kentriko(QWidget *parent = 0);
~kentriko();
public slots:
void anigma_arxiou();
void diabase();
private:
Ui::kentrikoClass ui;
QXmlStreamReader ena;
};
#endif // KENTRIKO_H
To copy to clipboard, switch view to plain text mode
the implementation
kentriko
::kentriko(QWidget *parent
){
ui.setupUi(this);
connect(ui.anigma,SIGNAL(clicked()),this,SLOT(anigma_arxiou()));
connect(ui.diabase,SIGNAL(clicked()),this,SLOT(diabase()));
}
kentriko::~kentriko()
{
}
void kentriko::anigma_arxiou(){
QFileDialog::getOpenFileName(this, tr
("anigma arxiou"),
QDir::currentPath(),tr
("arxia tipou (*.xml)"));
if (fileName.isEmpty())
return;
ui.textBrowser->append(fileName);
ena.setDevice(&file);
}
void kentriko::diabase(){
ena.readNext();
if (ena.isStartDocument()){
ui.textBrowser->append("start of document found");
};
//ena.readNext();
}
kentriko::kentriko(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
connect(ui.anigma,SIGNAL(clicked()),this,SLOT(anigma_arxiou()));
connect(ui.diabase,SIGNAL(clicked()),this,SLOT(diabase()));
}
kentriko::~kentriko()
{
}
void kentriko::anigma_arxiou(){
QString fileName =
QFileDialog::getOpenFileName(this, tr("anigma arxiou"),
QDir::currentPath(),tr("arxia tipou (*.xml)"));
if (fileName.isEmpty())
return;
QFile file(fileName);
ui.textBrowser->append(fileName);
file.open(QFile::ReadOnly | QFile::Text);
ena.setDevice(&file);
}
void kentriko::diabase(){
ena.readNext();
if (ena.isStartDocument()){
ui.textBrowser->append("start of document found");
};
//ena.readNext();
}
To copy to clipboard, switch view to plain text mode
:
and the xml that I am trying to read:
<adbook>
<contact email="kal@goteborg.se" phone="+46(0)31 123 4567" name="Kal" />
<contact email="ada@goteborg.se" phone="+46(0)31 765 1234" name="Ada" />
</adbook>
<adbook>
<contact email="kal@goteborg.se" phone="+46(0)31 123 4567" name="Kal" />
<contact email="ada@goteborg.se" phone="+46(0)31 765 1234" name="Ada" />
</adbook>
To copy to clipboard, switch view to plain text mode
when the diabase function is called my program crashes.
Any idea what might causing this?
Many thanks in advance.
Bookmarks