Home > Mobile >  Qt socket and the signal channel
Qt socket and the signal channel

Time:11-03

I write under qt socket
My design idea is this: socketserver side, when there is a connection in a QTcpSocket is new, and then give the QTcpSocket binding a readyread () signal, and put him in the QList save and close it, when the socket leave and signals and slots disconnect, in QList remove delete drop him at the same time, when there is another connection came in, so operation,
Problem, when the first connection to leave after the second connection in error: "free () : invalid size"



CodePudding user response:

First of all have a memory leak: currentsocket=new QTcpSocket QTcpSocket * (); This sentence can be removed, will directly nextPendingConnection pointer to it is ok, otherwise the new object has not been destroyed, but was covered by the new pointer address;
The cause of the error may be caused by the delete command, to socketlist. TakeAt (0). The deleteLater () a try,
Because the nextPendingConnection out object is managed by QTcpServer (its production, which destroyed), socket closed, of course, you can also call deleteLater to destroy by Qt mechanism, the early release of memory,

CodePudding user response:

Ok, to learn, thank you!
  •  Tags:  
  • Qt
  • Related