Reputation: 77
I can make a file and make my Qt project read and write to it .
But How can I make it create it's own text file for the first time then it writes and reads from and to it later for example i want it to write and read to and from this directory C:\Users\Administrator\Documents .
Upvotes: 1
Views: 368
Reputation: 4125
I will answer supposing that you are asking (don't know if I understood well, since your question is hardly understandable) how to create a file one time, then later, write and read from this file already created.
First, you have to give your file a name.
QString fileName = "C:\Users\Administrator\Documents\file.txt";
QFile file(fileName);
If your file is not already created : calling the function QFile::open(OpenMode mode) will create this file :
bool openOk = file.open(QIODevice::ReadWrite);
if (openOk)
{
// process
}
You can now write and read from your file.
Later, if you want to use your file again, just call this function again : if the file is already created, then you can read/write in this file.
Upvotes: 1