PDA

View Full Version : Create a file



bfr
28th January 2008, 04:17
How would I create a file with Qt? I know how to open an existing file with Qt using QFile::open(), but how would I actually create a file? QFile::open() doesn't seem to create files (when I'm opening them in QIODevice::ReadWrite mode).

ashukla
28th January 2008, 05:50
How would I create a file with Qt? I know how to open an existing file with Qt using QFile::open(), but how would I actually create a file? QFile::open() doesn't seem to create files (when I'm opening them in QIODevice::ReadWrite mode).
By the use
QFile file(fileName); of this you can create a file. As well as bool exists () const checks file exists or not.
Take a look of http://doc.trolltech.com/4.3/qfile.html .

seveninches
29th January 2008, 07:27
QFile::open() doesn't seem to create files (when I'm opening them in QIODevice::ReadWrite mode).

It does:



QFile file("/tmp/q");
file.open( QIODevice::WriteOnly);
file.write( "qq");
file.close();


I just run the above code, and it worked. Maybe you have permission problems? Did you check file.error() ?