0

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.

Tiana987642
  • 696
  • 2
  • 10
  • 28

1 Answers1

3

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();
}
m.s.
  • 16,063
  • 7
  • 53
  • 88