Hi all!
I have a server application that has a class inherited from QTcpServer and another that is inherited from the QThread and has a QTcpSocket variable. Lets just say class_tcpServer and class_serverThread.
Q_OBJECT
public:
class_tcpServer();
virtual ~class_tcpServer();
private:
class_tcpServer *ServerThread;
private slots:
void wait_for_data();
void free_slot(qint16);
};
class class_tcpServer : QTcpServer {
Q_OBJECT
public:
class_tcpServer();
virtual ~class_tcpServer();
private:
QTcpServer *tcpServer;
class_tcpServer *ServerThread;
private slots:
void wait_for_data();
void free_slot(qint16);
};
To copy to clipboard, switch view to plain text mode
the implementation has a slot that activates in case of a connection from the server. the slot looks like this:
void class_tcpServer::wait_for_data()
{
cout << "New connection made" << endl;
while(tcpServer->hasPendingConnections()){ //This controls pending connections
for (i = 0 ; i < max_connections ; i++) //Max connections is the number of sql licenses
{
if (connections[i] == 0)
{
cout << "Found empty slot for new connection" << endl;
ServerThread[i] = new EFrwServer_thread();
connect(ServerThread[i], SIGNAL(free_connection_slot(qint16)), this, SLOT(free_slot(qint16)));
ServerThread[i]->tcpSocket = tcpServer->nextPendingConnection();
ServerThread[i]->my_connection_number = i;
ServerThread[i]->start();
connections[i] = 1;
i = max_connections;
}
}
}
}
void class_tcpServer::wait_for_data()
{
cout << "New connection made" << endl;
while(tcpServer->hasPendingConnections()){ //This controls pending connections
for (i = 0 ; i < max_connections ; i++) //Max connections is the number of sql licenses
{
if (connections[i] == 0)
{
cout << "Found empty slot for new connection" << endl;
ServerThread[i] = new EFrwServer_thread();
connect(ServerThread[i], SIGNAL(free_connection_slot(qint16)), this, SLOT(free_slot(qint16)));
ServerThread[i]->tcpSocket = tcpServer->nextPendingConnection();
ServerThread[i]->my_connection_number = i;
ServerThread[i]->start();
connections[i] = 1;
i = max_connections;
}
}
}
}
To copy to clipboard, switch view to plain text mode
The thread does a query and then send the query in a QByteArray via the tcpSocket. That works just fine. At the end of the thread a signal is emited which will activate the slot free_slot(qint16) which simply sets the license to not used.
Everything works fine but my problem is that the memory goes up and up (which is fine as I don't know how to delete it).
How do I delete the object? or can someone tell me other solution?
thanks
Bookmarks