Is the aboutToQuit() signal of the QCoreApplication still supported in Qt 5.1.0?

The program starts upon opening a .txt file. Upon exit, I would like it to close the .txt file. Here are the code snippets:

MYRELAYSERVER:

void MyRelayServer::exitHandler()
{
    qDebug() << mFileName << " closed!" << mTcpPort;
    if (mDataLog)
        mTextStream << mFileName << " closed!" << mTcpPort;
    mFile.close();

}

MAIN:

#include <QCoreApplication>
#include "myrelayserver.h"
#include <QDebug>
#include <QObject>


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    MyRelayServer server(9999);
    QObject::connect(&a, SIGNAL(aboutToQuit()), &server, SLOT(exitHandler()));
    return a.exec();
}

However, it does not execute exitHandler.

It also does not display any intellisense from the signals of QCoreApplication a.

Answers


Had the same issue. Don't know the causes, but changing a to a pointer fixed it.

#include <QCoreApplication>
#include "myrelayserver.h"
#include <QDebug>
#include <QObject>


int main(int argc, char *argv[])
{
    QCoreApplication *a = new QCoreApplication (argc, argv);
    MyRelayServer server(9999);
    QObject::connect(a, SIGNAL(aboutToQuit()), &server, SLOT(exitHandler()));
    return a->exec();
}

It was available in autocomplete at least (in Qt Creator).


Properly designed classes in C++ implement the RAII concept. QFile does it, too. Thus you don't need to worry about closing the file manually. As long as you don't leak the instance of QFile object, it will be closed upon destruction.

Why won't you inspect the qcoreapplication.h header yourself?


Need Your Help

Using Django-taggit with django-rest-framework, i'm not able to save my tags

django django-rest-framework django-taggit

I'm trying to figure it out why when i submit my form, my tags are not saved in my db. Pretty new with the django-rest-framework and Django-taggit too, i think i'm doing something wrong :)