Hi all. This one is confusing me, so I’m asking for some input.
I have a method intended to create and populate a temporary file:
QTemporaryFile* JSHelper::getTemporaryFile(const QString& content) {
QTemporaryFile* tempFile = new QTemporaryFile("tmp.js");
tempFile->setAutoRemove(false);
if (tempFile->open())
{
QTextStream out(tempFile);
out << content << "\n";
tempFile->close();
}
else
qDebug() << "JSHelper::getTemporaryFile(): Could not open temp file";
return tempFile;
}
The problem is, the content of the populated file is always empty (at least on Windows XP). If I change the file object type to QFile, and open() with QIODevice::WriteOnly | QIODevice::Text (QTemporaryFile::open() takes no arguments), everything works great.
Does anyone have any clue of why I can’t write content to a QTemporaryFile like I’m trying to do? Mostly out of curiosity, as I will just use a regular file for now.
↧