PDA

View Full Version : Unable to write to file QFile



cuter
15th July 2009, 10:47
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFile file("testFile");
if(!file.open(QIODevice::WriteOnly))
qDebug()<<"Error opening the file";
QTextStream streamToWrite(&file);
const char* test = "Testing file write";
streamToWrite<<test;
file.close();
return a.exec();
}

nish
15th July 2009, 10:50
so whats the problem?? can to explain more... is the file created?

bismitapadhy
15th July 2009, 10:54
Are you Getting any error? The file is created or not? Try taking the content in a QString.

cuter
15th July 2009, 11:00
so whats the problem?? can to explain more... is the file created?


File is created in directory where sources are present. I expected it to be in the directory of executable and I was wrong. Able to write the strings properly using QTextStream, wondering why using QDataStream writes some extra characters to File

yogeshgokul
15th July 2009, 11:19
File is created in directory where sources are present. I expected it to be in the directory of executable and I was wrong. Able to write the strings properly using QTextStream, wondering why using QDataStream writes some extra characters to File
Because of encoding. QDataStream is used to write binary data, if your concern is only text better stuck with QTextStream.