I searched on the Internet, I found that with the two methods can realize communication,
Void Server: : incomingConnection (qintptr handle)
{
//(1)
//SocketThread * socket_thread=new SocketThread (handle);
//socket_thread - & gt; Start ().
//(2)
ServerTcpSocket * server_socket=new ServerTcpSocket (handle);
Server_socket - & gt; MoveToThread (new QThread ());
AddPendingConnection (server_socket);
}
The first is a server in the new connection, create a thread, thread has a socket, thread: : run () as follows,
Void SocketThread: : run ()
{
Socket ServerTcpSocket *=new ServerTcpSocket (ptr_);
The socket - & gt; WaitForReadyRead ();
The exec ();
}
The second is the server in the new connection, create a socket, if not add server_socket - & gt; MoveToThread (new QThread ()); This line of code, the socket is the client can read the news, plus moveToThread () cannot do,
Why the two are not?
CodePudding user response:
Original second moveToThread the thread didn't start () (), it can run, I want to use the first idea, thread: : run () specific to how to write can be received the socket when debugging: : readyRead ()