@@ -38,7 +38,15 @@ JsonConnection::JsonConnection(const QHostAddress& host, bool printJson , quint1
38
38
QObject::connect (_socket.get (), &QTcpSocket::connected, this , &JsonConnection::onConnected);
39
39
QObject::connect (_socket.get (), &QTcpSocket::readyRead, this , &JsonConnection::onReadyRead);
40
40
QObject::connect (_socket.get (), &QTcpSocket::disconnected, this , &JsonConnection::onDisconnected);
41
+
42
+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
41
43
QObject::connect (_socket.get (), &QTcpSocket::errorOccurred, this , &JsonConnection::onErrorOccured);
44
+ #else
45
+ QObject::connect (_socket.get (),
46
+ QOverload<QTcpSocket::SocketError>::of (&QTcpSocket::error),
47
+ this ,
48
+ &JsonConnection::onErrorOccured);
49
+ #endif
42
50
43
51
// init connect
44
52
connectToRemoteHost ();
@@ -588,17 +596,28 @@ QJsonObject JsonConnection::sendMessageSync(const QJsonObject &message, const QJ
588
596
589
597
// Ensure no duplicate connections by disconnecting previous ones
590
598
QObject::disconnect (this , &JsonConnection::isMessageReceived, nullptr , nullptr );
591
- QObject::disconnect (_socket.get (), &QTcpSocket::bytesWritten, nullptr , nullptr );
599
+
600
+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
592
601
QObject::disconnect (_socket.get (), &QTcpSocket::errorOccurred, nullptr , nullptr );
602
+ #else
603
+ QObject::disconnect (_socket.get (),
604
+ QOverload<QTcpSocket::SocketError>::of (&QTcpSocket::error),
605
+ nullptr , nullptr );
606
+ #endif
593
607
594
608
// Capture response when received
595
- connect (this , &JsonConnection::isMessageReceived, this , [&](const QJsonObject &reply) {
609
+ QObject:: connect (this , &JsonConnection::isMessageReceived, this , [&](const QJsonObject &reply) {
596
610
response = reply;
597
611
received = true ;
598
612
loop.quit (); // Exit event loop when response arrives
599
613
});
600
614
601
- connect (_socket.get (), &QTcpSocket::errorOccurred, this , [&loop](QAbstractSocket::SocketError /* error*/ ) {
615
+ #if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
616
+ QObject::connect (_socket.get (), &QTcpSocket::errorOccurred, this , [&loop](QTcpSocket::SocketError /* error*/ ) {
617
+ #else
618
+ QObject::connect (_socket.get (), QOverload<QTcpSocket::SocketError>::of (&QTcpSocket::error),
619
+ [&loop](QTcpSocket::SocketError /* error*/ ) {
620
+ #endif
602
621
loop.quit ();
603
622
});
604
623
0 commit comments