Results 1 to 4 of 4

Thread: QTemporaryFile and his destructor

  1. #1
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Arrow QTemporaryFile and his destructor

    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):

    Qt Code:
    1. #include <QtCore/QtGlobal>
    2. #include <QtCore/QtDebug>
    3. #include <QtCore/QCoreApplication>
    4. #include <QtCore/QTemporaryFile>
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QCoreApplication a(argc, argv);
    9. QTemporaryFile file(QLatin1String("mytemp"));
    10.  
    11. if (file.open()) {
    12. qDebug() << file.fileName();
    13. }
    14. return a.exec(); // if i change this to "return 0;" all be ok
    15. }
    To copy to clipboard, switch view to plain text mode 

    and this code works fine:

    Qt Code:
    1. #include <QtCore/QtGlobal>
    2. #include <QtCore/QtDebug>
    3. #include <QtCore/QCoreApplication>
    4. #include <QtCore/QTemporaryFile>
    5.  
    6. static QTemporaryFile file(QLatin1String("mytemp"));
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QCoreApplication a(argc, argv);
    11.  
    12. if (file.open()) {
    13. qDebug() << file.fileName();
    14. }
    15.  
    16. return a.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTemporaryFile and his destructor

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2008
    Location
    Russia, Moscow
    Posts
    86
    Thanks
    2
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4

    Default Re: QTemporaryFile and his destructor

    But why destructors calling when i use static global variable?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTemporaryFile and his destructor

    I don't know. They shouldn't be. Unless Qt installs some handler for its QObjects but I doubt it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.