Reputation: 585
I have problem with qt console application, destructor of MyServer class is not being called. Here is my simplified code:
#include <QtCore/QCoreApplication>
#include "MyServer/myserver.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
MyServer server;
server.startServer();
return a.exec();
}
myserver.h
class MyServer : public QTcpServer
{
Q_OBJECT
public:
MyServer(QObject *parent = nullptr);
~MyServer();
QFile* file;
}
myserver.cpp
MyServer::MyServer(QObject *parent)
: QTcpServer(parent)
{
file = new QFile("file.ini",this);
}
MyServer::~MyServer()
{
QSettings settings(file->fileName(), QSettings::IniFormat, this);
settings.beginGroup("testGroup");
settings.setValue("testValue", "asdf");
settings.endGroup();
}
Destructor should change the file.ini, but it doesnt.
Upvotes: 0
Views: 412
Reputation: 51832
MyServer::file
might be your problem. Are you opening that file for write access somewhere else in your code? Because QSettings
will attempt to also open the same file, and your two concurrent accesses to the same file might be clobbering its contents.
If you don't need MyServer::file
for anything, then get rid of it. QSettings
does not need QFile
. It only needs the filename.
Upvotes: 2