C++ write to resource file with qfile (QIODevice::write (QFile,“x”): device not open) [duplicate]
This question already has an answer here:
Writting in text file error, QT
1 answer
i have the following problem, i have an resource file called data.txt and i want to open it with write permission.
Im using QFile and QTextStream to work with it.
I can only open the File with ReadOnly Acces but not with ReadWrite or WriteOnly acces.
Export functions with similar code working fine its only not working on the resource file.
I already tried to change the front slashes to double backslashes, i runned hunderd times the qmake and rebuild, i restartet my computer and resotre the resource file.
I already checked alot of entries on Stack but wasnt able to find one that resolves my problem. (Most questions were spelling issues like only one backslash).
QFile file(":/savelocation/data.txt");
if (!file.exists())
{
qDebug()<<"File not exist";
}
file.open(QIODevice::ReadWrite | QIODevice::Text);
if (file.isOpen())
{
qDebug()<<"File is open";
QTextStream out(&file);
out<< "something" << endl;
}
else
{
qDebug()<<"File is not open";
}
file.close();
file.open(QIODevice::ReadOnly);
if (file.isOpen())
{
qDebug()<<"File is open as read only";
}
else
{
qDebug()<<"File is not open as read only";
}
file.close();
Actual result:
My Application output of the code:
File is not open
File is open as read only
Its only possible to open it as ReadOnly for me.
Before i implemented the if i got the following output:
QIODevice::write (QFile,":/savelocation/data.txt"): device not open
Expected result:
The file would be opened with write access.
Thanks in advance.
c++ read-write qfile resource-files qtextstream
marked as duplicate by drescherjm, genpfault, Community♦ Jan 7 at 12:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
Writting in text file error, QT
1 answer
i have the following problem, i have an resource file called data.txt and i want to open it with write permission.
Im using QFile and QTextStream to work with it.
I can only open the File with ReadOnly Acces but not with ReadWrite or WriteOnly acces.
Export functions with similar code working fine its only not working on the resource file.
I already tried to change the front slashes to double backslashes, i runned hunderd times the qmake and rebuild, i restartet my computer and resotre the resource file.
I already checked alot of entries on Stack but wasnt able to find one that resolves my problem. (Most questions were spelling issues like only one backslash).
QFile file(":/savelocation/data.txt");
if (!file.exists())
{
qDebug()<<"File not exist";
}
file.open(QIODevice::ReadWrite | QIODevice::Text);
if (file.isOpen())
{
qDebug()<<"File is open";
QTextStream out(&file);
out<< "something" << endl;
}
else
{
qDebug()<<"File is not open";
}
file.close();
file.open(QIODevice::ReadOnly);
if (file.isOpen())
{
qDebug()<<"File is open as read only";
}
else
{
qDebug()<<"File is not open as read only";
}
file.close();
Actual result:
My Application output of the code:
File is not open
File is open as read only
Its only possible to open it as ReadOnly for me.
Before i implemented the if i got the following output:
QIODevice::write (QFile,":/savelocation/data.txt"): device not open
Expected result:
The file would be opened with write access.
Thanks in advance.
c++ read-write qfile resource-files qtextstream
marked as duplicate by drescherjm, genpfault, Community♦ Jan 7 at 12:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
As per the documentation, resources are embedded in your binary file and are thus read-only, both conceptually and practically.
– Botje
Jan 2 at 15:27
So there is no way to write to these files?
– Max
Jan 2 at 15:30
1
No. You will have to save your data to a writable location on the filesystem, for example underQDir::home()
or the current working directoryQDir::current()
.
– Botje
Jan 2 at 15:32
Ok i will try it thank you, can you post this as answer that i can mark it, or should i just delete this question?
– Max
Jan 2 at 15:34
add a comment |
This question already has an answer here:
Writting in text file error, QT
1 answer
i have the following problem, i have an resource file called data.txt and i want to open it with write permission.
Im using QFile and QTextStream to work with it.
I can only open the File with ReadOnly Acces but not with ReadWrite or WriteOnly acces.
Export functions with similar code working fine its only not working on the resource file.
I already tried to change the front slashes to double backslashes, i runned hunderd times the qmake and rebuild, i restartet my computer and resotre the resource file.
I already checked alot of entries on Stack but wasnt able to find one that resolves my problem. (Most questions were spelling issues like only one backslash).
QFile file(":/savelocation/data.txt");
if (!file.exists())
{
qDebug()<<"File not exist";
}
file.open(QIODevice::ReadWrite | QIODevice::Text);
if (file.isOpen())
{
qDebug()<<"File is open";
QTextStream out(&file);
out<< "something" << endl;
}
else
{
qDebug()<<"File is not open";
}
file.close();
file.open(QIODevice::ReadOnly);
if (file.isOpen())
{
qDebug()<<"File is open as read only";
}
else
{
qDebug()<<"File is not open as read only";
}
file.close();
Actual result:
My Application output of the code:
File is not open
File is open as read only
Its only possible to open it as ReadOnly for me.
Before i implemented the if i got the following output:
QIODevice::write (QFile,":/savelocation/data.txt"): device not open
Expected result:
The file would be opened with write access.
Thanks in advance.
c++ read-write qfile resource-files qtextstream
This question already has an answer here:
Writting in text file error, QT
1 answer
i have the following problem, i have an resource file called data.txt and i want to open it with write permission.
Im using QFile and QTextStream to work with it.
I can only open the File with ReadOnly Acces but not with ReadWrite or WriteOnly acces.
Export functions with similar code working fine its only not working on the resource file.
I already tried to change the front slashes to double backslashes, i runned hunderd times the qmake and rebuild, i restartet my computer and resotre the resource file.
I already checked alot of entries on Stack but wasnt able to find one that resolves my problem. (Most questions were spelling issues like only one backslash).
QFile file(":/savelocation/data.txt");
if (!file.exists())
{
qDebug()<<"File not exist";
}
file.open(QIODevice::ReadWrite | QIODevice::Text);
if (file.isOpen())
{
qDebug()<<"File is open";
QTextStream out(&file);
out<< "something" << endl;
}
else
{
qDebug()<<"File is not open";
}
file.close();
file.open(QIODevice::ReadOnly);
if (file.isOpen())
{
qDebug()<<"File is open as read only";
}
else
{
qDebug()<<"File is not open as read only";
}
file.close();
Actual result:
My Application output of the code:
File is not open
File is open as read only
Its only possible to open it as ReadOnly for me.
Before i implemented the if i got the following output:
QIODevice::write (QFile,":/savelocation/data.txt"): device not open
Expected result:
The file would be opened with write access.
Thanks in advance.
This question already has an answer here:
Writting in text file error, QT
1 answer
c++ read-write qfile resource-files qtextstream
c++ read-write qfile resource-files qtextstream
asked Jan 2 at 15:25
MaxMax
185
185
marked as duplicate by drescherjm, genpfault, Community♦ Jan 7 at 12:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by drescherjm, genpfault, Community♦ Jan 7 at 12:55
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
1
As per the documentation, resources are embedded in your binary file and are thus read-only, both conceptually and practically.
– Botje
Jan 2 at 15:27
So there is no way to write to these files?
– Max
Jan 2 at 15:30
1
No. You will have to save your data to a writable location on the filesystem, for example underQDir::home()
or the current working directoryQDir::current()
.
– Botje
Jan 2 at 15:32
Ok i will try it thank you, can you post this as answer that i can mark it, or should i just delete this question?
– Max
Jan 2 at 15:34
add a comment |
1
As per the documentation, resources are embedded in your binary file and are thus read-only, both conceptually and practically.
– Botje
Jan 2 at 15:27
So there is no way to write to these files?
– Max
Jan 2 at 15:30
1
No. You will have to save your data to a writable location on the filesystem, for example underQDir::home()
or the current working directoryQDir::current()
.
– Botje
Jan 2 at 15:32
Ok i will try it thank you, can you post this as answer that i can mark it, or should i just delete this question?
– Max
Jan 2 at 15:34
1
1
As per the documentation, resources are embedded in your binary file and are thus read-only, both conceptually and practically.
– Botje
Jan 2 at 15:27
As per the documentation, resources are embedded in your binary file and are thus read-only, both conceptually and practically.
– Botje
Jan 2 at 15:27
So there is no way to write to these files?
– Max
Jan 2 at 15:30
So there is no way to write to these files?
– Max
Jan 2 at 15:30
1
1
No. You will have to save your data to a writable location on the filesystem, for example under
QDir::home()
or the current working directory QDir::current()
.– Botje
Jan 2 at 15:32
No. You will have to save your data to a writable location on the filesystem, for example under
QDir::home()
or the current working directory QDir::current()
.– Botje
Jan 2 at 15:32
Ok i will try it thank you, can you post this as answer that i can mark it, or should i just delete this question?
– Max
Jan 2 at 15:34
Ok i will try it thank you, can you post this as answer that i can mark it, or should i just delete this question?
– Max
Jan 2 at 15:34
add a comment |
1 Answer
1
active
oldest
votes
As per the documentation, resources are embedded in your binary file and are thus read-only, both conceptually and practically.
You will have to save your data to a writable location on the filesystem, for example under QDir::home()
or the current working directory QDir::current()
.
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
As per the documentation, resources are embedded in your binary file and are thus read-only, both conceptually and practically.
You will have to save your data to a writable location on the filesystem, for example under QDir::home()
or the current working directory QDir::current()
.
add a comment |
As per the documentation, resources are embedded in your binary file and are thus read-only, both conceptually and practically.
You will have to save your data to a writable location on the filesystem, for example under QDir::home()
or the current working directory QDir::current()
.
add a comment |
As per the documentation, resources are embedded in your binary file and are thus read-only, both conceptually and practically.
You will have to save your data to a writable location on the filesystem, for example under QDir::home()
or the current working directory QDir::current()
.
As per the documentation, resources are embedded in your binary file and are thus read-only, both conceptually and practically.
You will have to save your data to a writable location on the filesystem, for example under QDir::home()
or the current working directory QDir::current()
.
answered Jan 2 at 15:41
BotjeBotje
2,559914
2,559914
add a comment |
add a comment |
1
As per the documentation, resources are embedded in your binary file and are thus read-only, both conceptually and practically.
– Botje
Jan 2 at 15:27
So there is no way to write to these files?
– Max
Jan 2 at 15:30
1
No. You will have to save your data to a writable location on the filesystem, for example under
QDir::home()
or the current working directoryQDir::current()
.– Botje
Jan 2 at 15:32
Ok i will try it thank you, can you post this as answer that i can mark it, or should i just delete this question?
– Max
Jan 2 at 15:34