QT中socket跨线程调用的问题

void mythread::run()//connect to server
{
    c = new QTcpSocket();
    c->connectToHost("192.168.1.106",7777);
    while(true)
    {
         while(!flag);// if flag == true  send data
         char *p;
         QByteArray ba = message.toLatin1();
         cout << "thread: " << message.toStdString() << endl;
         p = ba.data();
         c->write(p);
         c->waitForBytesWritten();//fflush(stdout);
         flag = false;

         //message    chat$name$data
         QString fun = message.mid(0,4); // fun = "chat"
         if(fun != "chat") // login  register
         {
                 char buf[128] = {0};
                 cout << "read before" << endl;
                 while(! c->waitForReadyRead()); // false - not data   true - data
                 c->read(buf,128);// no block
                 string m(buf);
                 cout << "from server: " <<m << endl;
                 emit send_data(buf[0]);
                 if(buf[0] == '3')// login success  receive online name
                 {
                     char online_buf[256] = {0};
                     while(! c->waitForReadyRead());
                     c->read(online_buf,256);
                     string online_str(online_buf);
                     QString str = QString::fromStdString(online_str);
                     emit send_online_user(str);



                       //就是这里需要跳转到myfun函数中
                     QObject::connect(c,SIGNAL(readyRead()),this,SLOT(myfun()));
                     t = 1;
                     this->exec();//sleep  loop
                 }
         }


    }
}

 void mythread::myfun()
    {
            char buf[128] = {0};

            c->read(buf,128);
            string m(buf);
            cout << "from server: " <<m << endl;
            QString str = QString::fromStdString(m);
            emit send_recv_data(str);
    }

如上面的代码,一个简单的聊天室项目,在run函数中创建了一个socket实例用来写数据到服务器,登陆成功后需要跳转到myfun函数中接受服务器发来的消息,但是myfun函数就不属于run了,也就是说不是一个线程,socket又不可以跨线程调用,因此无法正常通信,这个要怎么改?

不知道你这个问题是否已经解决, 如果还没有解决的话:

如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 以帮助更多的人 ^-^