ich hab nun mal ein minimales projekt erstellt um den fehler auf ein minimum einzugrenzen.
hier mal mein code
test.h datei
Code: Alles auswählen
#ifndef TEST_H
#define TEST_H
#include <QWidget>
#include <QPushButton>
#include <QFile>
#include <QTextStream>
class TestClass : public QWidget
{
Q_OBJECT
public:
TestClass(QWidget *parent=0);
protected:
public slots:
void closeProject();
private:
QPushButton *button;
};
#endif
Code: Alles auswählen
#include <QDomDocument>
#include "test.h"
TestClass::TestClass(QWidget *parent)
: QWidget(parent)
{
button = new QPushButton( "Eintrag loeschen", this);
button->show();
connect( button, SIGNAL(clicked()), this, SLOT(closeProject()) );
}
void TestClass::closeProject()
{
QDomDocument doc;
//////////////////////////////// XML DATEI ÖFFNEN ////////////////////////////////////////////
QFile file( "project.xml" );
if( !file.open(QIODevice::ReadOnly) )
return;
if( !doc.setContent(&file) )
{
file.close();
return;
}
file.close();
//////////////////////////////// ELEMENT AUS XML LÖSCHEN ////////////////////////////////////////////
QDomNode project = doc.documentElement().firstChild();
while( !project.isNull() )
{
if( project.isElement() && project.nodeName() == "OPENEDFILES" )
{
QDomNode openedFiles = project.firstChild();
while( !openedFiles.isNull() )
{
if( openedFiles.isElement() && openedFiles.nodeName() == "FILE" )
{
project.removeChild( openedFiles );
}
openedFiles = openedFiles.nextSibling();
}
}
project = project.nextSibling();
}
//////////////////////////////// XML DATEI SPEICHERN ////////////////////////////////////////////
QFile XMLDatei( "project.xml" );
if(!XMLDatei.open(QIODevice::ReadWrite))
return;
QTextStream out( &XMLDatei );
out << doc.toString();
XMLDatei.close();
}
Code: Alles auswählen
<SE_PROJECT>
<OPENEDFILES>
<FILE name="eintrag1" />
<FILE name="eintrag2" />
<FILE name="eintrag3" />
<FILE name="eintrag4" />
<FILE name="eintrag5" />
</OPENEDFILES>
</SE_PROJECT>
ich hab das projekt zum testen nochmal im anhang mit angefügt.
danke im voraus!