From the doc, Detailed Description section
Code: Select all
// Within a function/method
QTemporaryFile file;
if (file.open()) {
// file.fileName() returns the unique file name
}
// QTemporaryFile destructor removes the temporary file as it goes out of scope.
Code: Select all
void Task::run()
{
// Do processing here
qDebug() << "Hello World!";
QTemporaryFile file(this);
if (file.open())
{
qDebug() << "temporary file name: " << file.fileName();
}
else
{
qDebug() << "failed to open temporary file";
}
emit finished();
}
Code: Select all
roland@roland-amd-desktop:~/Projects/cs_hello_debug$ ./cs_hello
Hello World!
QFSFileEngine::open() No file name specified
failed to open temporary file
roland@roland-amd-desktop:~/Projects/cs_hello_debug$
Code: Select all
void Task::run()
{
// Do processing here
qDebug() << "Hello World!";
QTemporaryFile file;
if (file.open())
{
qDebug() << "temporary file name: " << file.fileName();
}
else
{
qDebug() << "failed to open temporary file";
}
emit finished();
}
Code: Select all
roland@roland-amd-desktop:~/Projects/cs_hello_debug$ ./cs_hello
Hello World!
QFSFileEngine::open() No file name specified
failed to open temporary file
roland@roland-amd-desktop:~/Projects/cs_hello_debug$