Tiana987642
Tiana987642

Reputation: 754

QTcpSocket not emit any error or connected signals

I have a small project which send some data over network using QTcpSocket. The server works fine but the client(code here) seems does nothing. If I set breakpoint at tcpSocket.connectToHost("127.0.0.1",port); it does jump in, but not any slots I defined.

I can't figure out what's wrong. I think the environment is ok because I can build 2 working examples from Qt GUI Programming

Any ideas are appreciated.

Upvotes: 0

Views: 146

Answers (1)

m.s.
m.s.

Reputation: 16324

You do not have a QApplication instance and thus no event loop which does all the event / signal&slot handling.

So you at least need a QCoreApplication instance like this in main.cpp:

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    Client client;
    client.connectToServer();

    return a.exec();
}

Upvotes: 3

Related Questions