tags:

views:

58

answers:

3

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)

A: 

The problem is in this line:

QFile out(":/test.txt");

The file path is wrong. To create the file in the same directory as the executable try it this way:

QFile out("./test.txt");

Edit: spelling

bruno
That'd be not the same directory as the executable, but the working directory.
Frank
+2  A: 

":/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".

Roku
A: 

You need to change your QFile constructor argument

QFile out(":/test.txt");

to a correct path that could be

QFile out("./test.txt");

or

QFile out("C:/test.txt");

Longfield