Effendi
Effendi

Reputation: 98

QApplication destructor is not called properly

I derived an application class from QApplication in order to reimplement some methods. Here is the code:



    class MyApplication : public QApplication
    {
        Q_OBJECT
    private:
    public:
        //...
        virtual ~MyApplication();   
    };

    MyApplication::~MyApplication()
    {
        qDebug("~MyApp1");
        try
        {
            //some potentially long operations
        }
        catch(...)
        {
            qDebug("~MyApp  Exception");
        }

        qDebug("~MyApp2");
    }

    int main(int argc, char *argv[])
    {
        int returnValue = 1;
        {
            MyApplication app(argc, argv);
            returnValue = app.exec();
        }
        return returnValue;
    }

The problem is that I tend to get different qDebug outputs. I always get ~MyApp1 printed, but only sometimes ~MyApp2. What could be the reason? It seems, that when the App is closing, Qt does not let the whole destructor to be done. How can I make the program wait till the destructor is finished?

Upvotes: 2

Views: 741

Answers (1)

DerManu
DerManu

Reputation: 720

The QApplication Destructor is called properly, it's just that qDebug probably shouldn't/can't be used at such a late state of the application. Try using cout/cin streams directly (iostreams/printf).

Upvotes: 2

Related Questions