Search code examples
c++qtqfile

QFile open file for writing fails


I'm trying to open file and write some text data into it.

QFile out(":/test.txt");
if (!out.open(QIODevice::ReadWrite)) {
    QMessageBox msgBox;
    msgBox.setText(out.errorString());
    msgBox.exec();
    return;
}

But it fails with "Unknown error". (Qt 4.6, Wnidows XP SP3)


Solution

  • ":/test.txt" is a name of a resource file embedded to the executable and you can't write to it. Change the file name for example to "C:/test.txt".