View Full Version : How to create File in a given Dir ?
revellix
7th October 2011, 16:23
Hi,
I want to create a File in a given Directory.
f.e.:
QFile myFile("C:/Home/File.txt")
doing it the way above Qt doesnt create any File. I want to create a QDir (that works fine) and save all created Strems inside this QDir. Can anybody help?
wysota
7th October 2011, 16:31
Open the file in write mode.
revellix
7th October 2011, 16:36
this is my code:
QString str = QCoreApplication::applicationDirPath()+"/hello/";
qDebug() << str;
QFile Druck_m(str+"Druck.m");
Druck_m.open(QIODevice::WriteOnly);
QTextStream dataDruck_m(&Druck_m);
........stream
wysota
7th October 2011, 18:07
And? What about it?
stampede
7th October 2011, 18:12
Does the "hello" dir exists ? If not, you will probably get QFile::OpenError when trying to create a file in a non-existing directory.
You need to check return values, they can help a lot:
QString str = QCoreApplication::applicationDirPath()+"/hello/";
QFile Druck_m(str+"Druck.m");
if( Druck_m.open(QIODevice::WriteOnly) ){
QTextStream dataDruck_m(&Druck_m);
...
} else{
qDebug() << "file not opened, error code: " << Druck_m.error(); // error codes are desribed in QFile documentation
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.