I've been having trouble getting my client/server code to work. Here's a little test program I put together to test my sanity.

server.hpp:
Qt Code:
  1. #include <QObject>
  2. class QTcpServer;
  3.  
  4. class Server : public QObject {
  5. Q_OBJECT
  6. public:
  7. Server();
  8. bool done();
  9. private slots:
  10. void newConnection();
  11. private:
  12. bool d;
  13. };
To copy to clipboard, switch view to plain text mode 

server.cpp:
Qt Code:
  1. #include "server.hpp"
  2. #include <QTcpServer>
  3. #include <QTcpSocket>
  4.  
  5. Server::Server() {
  6. d = false;
  7. s = new QTcpServer(this);
  8. s->listen(QHostAddress::Any, 123456);
  9. connect(s,SIGNAL(newConnection()),
  10. this,SLOT(newConnection()) );
  11. }
  12.  
  13. bool Server::done() {
  14. return d;
  15. }
  16.  
  17. void Server::newConnection() {
  18. QTcpSocket * sock = s->nextPendingConnection();
  19. qWarning() << "Got one.";
  20. delete sock;
  21. }
To copy to clipboard, switch view to plain text mode 

servermain.cpp:
Qt Code:
  1. #include "server.hpp"
  2.  
  3. int main() {
  4. Server s;
  5. while (!s.done()) {
  6. }
  7. return 0;
  8. }
To copy to clipboard, switch view to plain text mode 

clientmain.cpp:
Qt Code:
  1. #include <QTcpSocket>
  2. #include <iostream>
  3.  
  4. int main() {
  5. char c;
  6. QTcpSocket * sock;
  7.  
  8. while (std::cin >> c) {
  9. switch(c) {
  10. case 'c':
  11. sock = new QTcpSocket();
  12. sock->connectToHost("127.0.0.1",123456);
  13. if(sock->waitForConnected()) {
  14. qWarning() << "OK";
  15. }
  16. else {
  17. qWarning() << "NO";
  18. }
  19. delete sock;
  20. };
  21. }
  22. return 0;
  23. }
To copy to clipboard, switch view to plain text mode 

If I fire up both programs in separate terminals, the client coughs out "OK" every time you enter a 'c', but the server never does anything, and in a debugger the newConnection slot is never executed. What's going on?

Thanks already.