Qt笔记-解决QSocketNotifier: Multiple socket notifiers for same socket xxx and type Read问题
生活随笔
收集整理的這篇文章主要介紹了
Qt笔记-解决QSocketNotifier: Multiple socket notifiers for same socket xxx and type Read问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Qt中的socket有個descriptor的概念,這個descriptor就代表socket。
報這個錯誤是因為,你程序里面2個socket都綁了同一個descriptor。所以出現了問題。
我的遇到的是這樣的。
①
void QSSLServer::incomingConnection(qintptr socketDescriptor) {QSslSocket *sslSocket = new QSslSocket(this);..................addPendingConnection(sslSocket); }addpending相關:
?這里如果用信號與槽就必須這樣用
void QSSLServer::rx() {QTcpSocket* clientSocket = qobject_cast<QTcpSocket*>(sender());..............//再發一條數據clientSocket->write("Hello Client"); }而不能
QTcpSocket tcpSocket; tcpSocket.setSocketDescriptor(num);②
在多線程的服務端中不要再調用addPendingConnection,直接在此處調用連接池。在線程中直接進行TCP相關的操作。
總結
以上是生活随笔為你收集整理的Qt笔记-解决QSocketNotifier: Multiple socket notifiers for same socket xxx and type Read问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Vue笔记-vue3中.en.dev文件
- 下一篇: Qt文档阅读笔记-QFuture官方解析