LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Qt asynchronous sockets problem (https://www.linuxquestions.org/questions/programming-9/qt-asynchronous-sockets-problem-686308/)

greeklegend 11-26-2008 06:52 AM

Qt asynchronous sockets problem
 
Hey everybody,
I'm trying to write a simple, four-player card game to play over the network using the QT4 toolkit. I've set up a protocol (client/server) such that I always know when I must do sending and when I must do recieving. Unfortunatly using the sockets system is causing me epic headaches!
The problem is, I don't want to block the GUI by using QTcpSocket::waitForReadyRead(). What I had in mind was using blocking I/O in a thread whenever it was necessary and catching the thread's terminate signal in my main loop...but then I have no way of knowing which socket (player) I just finished sending data to!
Idealy, i'd like to do something like this...

(in the server)
Code:

class MyIOThread : public QThread
{
public:
QTcpSocket* socket;
....other game data....
int result;
void run(); };

void MyIOThread::run(){ some code using data and socket->read(); set this.result; return;}

...ive decided some recieving needs to be done from the client...
MyIOThread* thethread = new MyIOThread;
thethread->socket = some_socket_somewhere;
connect(thethread, SIGNAL(terminate()), this, SLOT(aslot()));

void aslot()
{
do soemthing with MyIOThread_instance_that_I_declared_before.result
}

So is there a way i can find out exactly what instance of a class fired the signal i'm now handling in that slot?
Thanks


All times are GMT -5. The time now is 06:29 PM.