QTcpServer connected signal does not invoke corresponding slot in GUI application!!!!
I have tried so many things but still problem persists.
I can see that server is started and can connect using telnet. But it does not invoke new connection slot. What seems to be wrong?
main.cpp
Code:
int main(int argc, char *argv[])
{
core = new QGCCore(firstStart, argc, argv);
val = core->exec();
}
QGCCore.cpp:
Code:
QGCCore
::QGCCore(bool firstStart,
int &argc,
char* argv
[]) : QApplication(argc, argv
),
restartRequested(false),
welcome(NULL)
{
Server s;
s.listen();
}
server.cpp
Code:
#include "server.h"
#include <QTcpServer>
#include <QTcpSocket>
#include <cstdio>
#include <QDebug>
{
connect(server, SIGNAL(newConnection()),
this, SLOT(on_newConnection()));
qDebug() << "Server instance created";
}
void Server::listen()
{
qDebug() << "Server listening to 1234";
}
void Server::on_newConnection()
{
qDebug() << "New connection made!";
}
Re: QTcpServer connected signal does not invoke corresponding slot in GUI application
By the time event processing starts there is no longer any slot to call, because the receiver object is already gone.
The Server object is created, its listen is called and then it is destroyed.
If you want your Server instance to be a signal receiver, don't destroy it, keep it :)
Cheers,
_
Re: QTcpServer connected signal does not invoke corresponding slot in GUI application
Thanks anda_skoa so much..
I created a static singleton instance of server which stayed around..and signal/slot for new connection works like charm..
Newbie to c++, so still struggling with scopes...
:D
Re: QTcpServer connected signal does not invoke corresponding slot in GUI application
It might have been easier to just add a Server member to QGCCore class :)
Or directly use the QTcpServer inside QGCore and connecting to its slots.
Cheers,
_