开发者

QFile open file for writing fails

开发者 https://www.devze.com 2023-01-11 07:38 出处:网络
I\'m trying to open file and write some text data into it. QFile out(\":/test.txt\"); if (!out.open(QIODevice::ReadWrite开发者_StackOverflow中文版)) {

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

QFile out(":/test.txt");
if (!out.open(QIODevice::ReadWrite开发者_StackOverflow中文版)) {
    QMessageBox msgBox;
    msgBox.setText(out.errorString());
    msgBox.exec();
    return;
}

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


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


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");

0

精彩评论

暂无评论...
验证码 换一张
取 消