WebsocketClient: fix potential crash

This commit is contained in:
tobtoht 2022-03-11 16:03:06 +01:00
parent 005de6ed4f
commit efda517503
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
2 changed files with 7 additions and 0 deletions

View file

@ -117,3 +117,9 @@ void WebsocketClient::onbinaryMessageReceived(const QByteArray &message) {
emit WSMessage(object);
}
WebsocketClient::~WebsocketClient() {
// webSocket may fire QWebSocket::disconnected after WebsocketClient is destroyed
// explicitly disconnect to prevent crash
webSocket.disconnect();
}

View file

@ -15,6 +15,7 @@ class WebsocketClient : public QObject {
public:
explicit WebsocketClient(QObject *parent = nullptr);
~WebsocketClient() override;
void start();
void restart();
void stop();