PDA

View Full Version : QTcpServer and QThread signal/slot problem



Diph
28th July 2009, 14:40
Hi.

I'm trying to implement tcpserver which runs alongside the GUI program. Here are the classes:

MainWindow:

MainWindow::MainWindow()
{
serverThread = new ServerThread(this);
serverThread->start();
}

ServerThread(QThread):

void ServerThread::run()
{
server = new Server(NULL);
server->listen(QHostAddress::Any, DEF_PORT);
//How to connect MainWindow slots with Server signals?
exec();
}

Server(QTcpServer):

Server::Server(QObject *parent) : QTcpServer(parent)
{
connect(this, SIGNAL(newConnection()), this, SLOT(addConnection()));
}

How do I connect MainWindow slots with Server signals and am I doing this the right way?

wysota
28th July 2009, 14:55
What's the purpose of having the server in a dedicated thread?

Diph
28th July 2009, 15:25
What's the purpose of having the server in a dedicated thread?
MainWindow is basically a music player and the server sends playback information etc. to the client. So I can use just signals and slots? The GUI doesn't freeze?

wysota
28th July 2009, 16:22
No, the GUI will be fine, you can use a single thread.

Diph
28th July 2009, 19:34
No, the GUI will be fine, you can use a single thread.
Ok, thanks.