network in qt6
-
Hello,
I have been following network learning, but there was no success. I use qt 6.5 LTS along with qt creator 10.0.0 on Windows 11. Here are two programs.
client
server
The error I get isqt.core.qobject.connect: QObject::connect: No such signal QTcpSocket::error(QAbstractSocket::SocketError) in ..\user.cpp:48 qt.core.qobject.connect: QObject::connect: (receiver name: 'user')
Your help is appreciated
-
Hello,
I have been following network learning, but there was no success. I use qt 6.5 LTS along with qt creator 10.0.0 on Windows 11. Here are two programs.
client
server
The error I get isqt.core.qobject.connect: QObject::connect: No such signal QTcpSocket::error(QAbstractSocket::SocketError) in ..\user.cpp:48 qt.core.qobject.connect: QObject::connect: (receiver name: 'user')
Your help is appreciated
@Vahid-Ajallooeian said in network in qt6:
qt.core.qobject.connect: QObject::connect: No such signal QTcpSocket::error(QAbstractSocket::SocketError) in ..\user.cpp:48
qt.core.qobject.connect: QObject::connect: (receiver name: 'user')This error comes from a wrong or failed
connect
statement.It's sad that "learning examples" are still using the macro style connection and not the function based connect statement.
Then code with failed connections wouldn't even compile.So back to the issue, which has the same origin: old code.
The example was probably made for Qt4 or an early Qt5.Checking line 48 in
user.cpp
from client:connect(m_pClientsocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));
Since Qt 5.15 onwards there is no
error(QAbstractSocket::SocketError)
signal inQAbstractSocket
anymore.
There is anerror()
function, which returns the last error, but the signal to do what the code should do, is callederrorOccurred(QAbstractSocket::SocketError)
- https://doc.qt.io/qt-5/qabstractsocket.html#errorOccurred
- https://doc.qt.io/qt-6/qabstractsocket.html#errorOccurred
- https://doc.qt.io/qt-5/qabstractsocket.html#error
The solution could look like this:
connect(m_pClientsocket, &QTcpSocket::errorOccurred, this, &user::displayError);
-
@Vahid-Ajallooeian said in network in qt6:
qt.core.qobject.connect: QObject::connect: No such signal QTcpSocket::error(QAbstractSocket::SocketError) in ..\user.cpp:48
qt.core.qobject.connect: QObject::connect: (receiver name: 'user')This error comes from a wrong or failed
connect
statement.It's sad that "learning examples" are still using the macro style connection and not the function based connect statement.
Then code with failed connections wouldn't even compile.So back to the issue, which has the same origin: old code.
The example was probably made for Qt4 or an early Qt5.Checking line 48 in
user.cpp
from client:connect(m_pClientsocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));
Since Qt 5.15 onwards there is no
error(QAbstractSocket::SocketError)
signal inQAbstractSocket
anymore.
There is anerror()
function, which returns the last error, but the signal to do what the code should do, is callederrorOccurred(QAbstractSocket::SocketError)
- https://doc.qt.io/qt-5/qabstractsocket.html#errorOccurred
- https://doc.qt.io/qt-6/qabstractsocket.html#errorOccurred
- https://doc.qt.io/qt-5/qabstractsocket.html#error
The solution could look like this:
connect(m_pClientsocket, &QTcpSocket::errorOccurred, this, &user::displayError);
Dear @Pl45m4
Thank you for your follow-up.
The terminal error has gone, but messages are not transmitted between the server and the client. -
Dear @Pl45m4
Thank you for your follow-up.
The terminal error has gone, but messages are not transmitted between the server and the client.@Vahid-Ajallooeian said in network in qt6:
The terminal error has gone, but messages are not transmitted between the server and the client.
Debug and check what happens.
I would also check your whole project and compare it with the Qt6.5 documentation to see if there is more deprecated stuff