PDA

View Full Version : QTemporaryFile and his destructor



SABROG
19th May 2009, 15:50
I have strange behaviour when using QTemporaryFile. Temp files don't delete with this code when i exit from console program from Ctr+C or click on _[]"X" (Windows):



#include <QtCore/QtGlobal>
#include <QtCore/QtDebug>
#include <QtCore/QCoreApplication>
#include <QtCore/QTemporaryFile>

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QTemporaryFile file(QLatin1String("mytemp"));

if (file.open()) {
qDebug() << file.fileName();
}
return a.exec(); // if i change this to "return 0;" all be ok
}


and this code works fine:



#include <QtCore/QtGlobal>
#include <QtCore/QtDebug>
#include <QtCore/QCoreApplication>
#include <QtCore/QTemporaryFile>

static QTemporaryFile file(QLatin1String("mytemp"));

int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);

if (file.open()) {
qDebug() << file.fileName();
}

return a.exec();
}

wysota
19th May 2009, 19:40
If you kill the application, it is aborted immediately so no destructors are called. You can intercept those situations if you want and act accordingly.

SABROG
19th May 2009, 19:50
But why destructors calling when i use static global variable?

wysota
19th May 2009, 19:55
I don't know. They shouldn't be. Unless Qt installs some handler for its QObjects but I doubt it.