Edit an XML file from Qt GUI

  • Hai everybody,
    I am a student and pretty new to Qt. I just want to make a GUI from which i can make changes to an XML file 'myData.xml' stored at "home/me/Qt/".

           <finished>0</finished> <!-- 1 if finished, 0 if not -->

    I have 2 check boxes (yes and No) in the GUI for the 'finished?' option. When i check the 'yes' box, the value 1 must be set and the file must be saved (overwritten) at the same place.
    Given below is the checkBox_pressed function:

    void MainWindow::on_checkBox_pressed()
        QFile file("home/me/Qt/config.xml");
        if (!file.open(QIODevice::ReadWrite | QIODevice::Text))
            qDebug()<<"File not found";
        QDomDocument document;
        QDomElement root = document.documentElement();
        // Write changes to same file
        QTextStream stream;
        document.save(stream, 4);

    Am i missing something here? I doubt if i have provided the file path correctly.
    Please give me some valuable insights.

  • Lifetime Qt Champion


    Did you check the content of your QDomDocument instance after your modifications ?
    Are you sure that it's child node number two that you should be modifying ?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.