Hi faftjuicymole,
Putting moveToThread(this) in the constructor actually made the event loop fail to work at all. Actually I don't understand how that should work--putting it in the thread constructor just moves the thread to itself, right? Maybe you can take a look at these snippets and see what the problem is:
{
// moveToThread(this);
}
void MyThread::run()
{
myserver = new QLocalServer();
QLocalServer::removeServer("myserver");
myserver->listen("myserver");
connect(myserver,SIGNAL(newConnection()),this,SLOT(NewConnection()));
lsock_out = new QLocalSocket(myserver);
lsock_in = new QLocalSocket(myserver);
// gl_proc->moveToThread(this);
myprocess->start("myproc_filename");
exec();
}
void MyThread::NewConnection()
{
static int ct=0;
switch (ct++%2) //This switch is so that the first connection gets picked up as the write socket and the second as the read socket--
//That's how things are coded on the other end. (I.e., this function gets called twice)
{
case 0:
lsock_out = myserver->nextPendingConnection();
break;
case 1:
lsock_in = myserver->nextPendingConnection();
connect(lsock_in,SIGNAL(readyRead()),this,SLOT(ReadyRead()));
break;
}
}
void MyThread::ReadyRead()
{
//Read from the socket connection, lsock_in...
}
MyThread::MyThread() : QThread()
{
// moveToThread(this);
}
void MyThread::run()
{
myserver = new QLocalServer();
QLocalServer::removeServer("myserver");
myserver->listen("myserver");
connect(myserver,SIGNAL(newConnection()),this,SLOT(NewConnection()));
lsock_out = new QLocalSocket(myserver);
lsock_in = new QLocalSocket(myserver);
myprocess = new QProcess();
// gl_proc->moveToThread(this);
myprocess->start("myproc_filename");
exec();
}
void MyThread::NewConnection()
{
static int ct=0;
switch (ct++%2) //This switch is so that the first connection gets picked up as the write socket and the second as the read socket--
//That's how things are coded on the other end. (I.e., this function gets called twice)
{
case 0:
lsock_out = myserver->nextPendingConnection();
break;
case 1:
lsock_in = myserver->nextPendingConnection();
connect(lsock_in,SIGNAL(readyRead()),this,SLOT(ReadyRead()));
break;
}
}
void MyThread::ReadyRead()
{
//Read from the socket connection, lsock_in...
}
To copy to clipboard, switch view to plain text mode
So, what is happening is that the readyRead() events aren't getting handled while the main event loop is blocking (otherwise, communication is fine). What have I done wrong? Thank you!
Matt
Bookmarks