QFile does not overwrite the

i have a program here and it does not overwrite as it should it say file is not open

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
      QFile file(":/Soruce/list.txt");  // the location by the way is in QT resource
    if (!file.open(QFile::ReadWrite|QFile::Text|QFile::Truncate))
    {
        qDebug()<<"File not created";
    }

    else
    {
    QTextStream out(&file);

    qDebug()<<"succesful getting updating";

    for(int i =0;i<=list.size();i++)
    {
        QString temp;
        QString temp2;
        temp= temp.number(list[i].id);
        out<<temp;
        temp2= temp2.number(list[i].balance);
        out<<temp<<endl<<temp2<<endl;

    }
    }



if you can help me thank you very much
read the first line and write it to the screen to be sure maybe?
Soruce is this a typo here or in your real code? or correct?
if (!file.open(QFile::ReadWrite|QFile::Text|QFile::Truncate))

Did you find that code in the official documentation? Does this work instead?
if (!file.open(QIODevice::ReadWrite|QIODevice::Text|QIODevice::Truncate))

Anyway, in the documentation is specified:
QIODevice::Truncate If possible, the device is truncated before it is opened.

Does your external device allow writing operation? Are you able to write on that file from your program, apart from truncating it?
Topic archived. No new replies allowed.