Home > Mobile >  Using inheritance QThread rewrite the run () method, signal inside groove QTcpsocket: : readyRead ()
Using inheritance QThread rewrite the run () method, signal inside groove QTcpsocket: : readyRead ()

Time:10-09

Because to BuKa interface, before creating MainWindow creates a wrapper QTcpsocket class (inherited QThread and inside signal channel), and then Start (). Connect to other server and send data there is no problem. But the other party to send data over the readyRead () did not trigger the corresponding slot function... At present only in the write () to send data after using the while (1) {waitForReadyRead (1); Read (); } card waiting for receiving data... Signal channel tried Qt: : DirectConnection and Qt: : QueuedConnection are no..

The use of this is wrong, please?

CodePudding user response:

Your readyRead () corresponding to the groove function is realized in QTcpsocket class, I was a thread inside, there is no problem

CodePudding user response:

reference 1/f, today also to its feet oh full response:
your readyRead () corresponding to the groove function is realized in QTcpsocket class, I was a thread inside, there is no problem


Not so good. I described is the same thread,
1. Enclosed the QTcpsocket is class A, members of A class have QTcpsocket m_MyTcpsocket. Inside A constructor to perform QObject: : connect (& amp; M_MyTcpsocket, SIGNAL (readyRead ()), & amp; M_MyTcpsocket, SLOT (MyReceiveData ())); And encapsulate the connect and write them into a MySendData (0 function, public slots: add the void MyReceiveData ();

2. Class B inherits the QThread. There were A member of the class A pointer MyTcpsocket * p. The main () code execution is B * pb=new B (); B - & gt; Start (). B: : run () to initialize A p=new MyTcpsocket (), and then execute p - & gt; MySendData (), the connection and send all have no problem, this time the other server returned, did not enter the MyReceiveData (); .

CodePudding user response:





reference 1/f, today also to its feet oh full response:
your readyRead () corresponding to the groove function is realized in QTcpsocket class, I was a thread inside, there is no problem



Write wrong, is not very good. I described is the same thread,
1. Enclosed the QTcpsocket is class A, members of A class have QTcpsocket m_MyTcpsocket. Inside A constructor to perform QObject: : connect (& amp; M_MyTcpsocket, SIGNAL (readyRead ()), this , SLOT (MyReceiveData ())); And encapsulate the connect and write them into a MySendData (0 function, public slots: add the void MyReceiveData ();

2. Class B inherits the QThread. There were A member of the class A pointer MyTcpsocket * p. The main () code execution is B * pb=new B (); B - & gt; Start (). B: : run () to initialize A p=new MyTcpsocket (), and then execute p - & gt; MySendData (), the connection and send all have no problem, this time the other server returned, did not enter the MyReceiveData (); ,,,


CodePudding user response:

You can look at your application information, if there is a similar this kind of mistake: XXX in the company's thread. Or: the connect signal slot error and so on

CodePudding user response:

reference 4 floor donwmufromdying response:
you can look at your application information, if there is a similar this kind of error: in the XXX company's thread. Or: the connect signal slot error such as



Beginning has been discovering, and finally kill all of the file such as the make, it is ok to recompile. Similar to what you said in the XXXX behind another thread. This search information seems to be a multi-threaded for a class of Q_Object in it? !
  •  Tags:  
  • Qt
  • Related