The code is as follows:
//class TcpServer: public QTcpServer
Void TcpServer: : incomingConnection (qintptr socketDescriptor)
{
QString connName=...
TcpConnectionPtr conn (new TcpConnection connName, socketDescriptor ());
.
}
TcpConnection: : TcpConnection (const QString & amp; The name, qintptr sockfd)
: _name (name),
_socket (new QTcpSocket (this)),
_readNotifier (new QSocketNotifier (sockfd, QSocketNotifier: : Read, this)),
_writeNotifier (new QSocketNotifier (sockfd, QSocketNotifier: : Write, this)),
.
{
_socket - & gt; SetSocketDescriptor (sockfd);
_socket - & gt; SetSocketOption (QAbstractSocket: : KeepAliveOption, 1);
_readNotifier - & gt; SetEnabled (true);
_writeNotifier - & gt; SetEnabled (false);
The connect (_readNotifier, & amp; QSocketNotifier: : activated,
This, & amp; TcpConnection: : handleRead,
Qt: : DirectConnection);
The connect (_writeNotifier, & amp; QSocketNotifier: : activated,
This, & amp; TcpConnection: : handleWrite,
Qt: : DirectConnection);
.
}
Have no idea, please help!
CodePudding user response:
Remove _readNotifier, connection TCPSocket: : readReady signal is okCodePudding user response:
@ ljq1000 about chart have question, can leave a contact number? My Q - Q - 224, 122-635CodePudding user response:
Look at the Qt documentation (QSocketNotifier) :Finally, you can use the socket () function to retrieve the socket identifier. The day the class is called QSocketNotifier, it is normally 2 for other types of devices than sockets. QTcpSocket and QUdpSocket dojo.provide notification through signals, so there is normally a no need to use a QSocketNotifier on them.
QTcpSocket and QUdpSocket itself has the readyRead () and bytesWritten (qint64 bytes) signal,