QTcpService based server-clint
-
I recently started to work with qt creator and i got stuck the some error which i don't know why i am getting.
I the following line of code i am trying to connect a virtual client to the server by using the (IP address - 127.0.0.1), but when i click on connect button it shows the error "qt.core.qobject.connect: QObject::connect: No such signal QTcpSocket::error(QAbstractSocket::SocketError)" and "
qt.core.qobject.connect: QObject::connect: (receiver name: 'Dialog')".If anyone have any solution or suggestion please let me know.
Code lines -
void Dialog::on_pushButtonConnect_clicked()
{
m_pClientsocket->connectToHost(ui->textEditIP->toPlainText(),quint16(ui->textEditPort->toPlainText().toInt()) );
connect(m_pClientsocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError)));}
-
Since you use Qt6 (I guess, you did not menion) I would say it's correct - there is no such a signal (anymore): https://doc.qt.io/qt-6/qabstractsocket.html#signals
Please use the new signal/slot syntax to catch such errors on compile time.
-
@Aijaz error() is not a signal.
What you want is: https://doc.qt.io/qt-5/qabstractsocket.html#errorOccurred -
@Christian-Ehrlicher thanks for the suggestion, i will definitely try do d that.
-
From the above suggestion i understood that there will be a change in syntax, but i exactly don't know what changes i should i make.
Bellow is the change in code i tried to do,void Dialog::on_pushButtonConnect_clicked()
{
m_pClientsocket->connectToHost(ui->textEditIP->toPlainText(),quint16(ui->textEditPort->toPlainText().toInt()) );connect(ui->m_pClientsocket, &error::SocketError, ui->this, &displayError::SocketError);
}
(And now i am even getting even more error's)can anyone suggest me the correct way to do it.
-
@Aijaz said in QTcpService based server-clint:
connect(ui->m_pClientsocket, &error::SocketError, ui->this, &displayError::SocketError);
For syntax please read New Signal Slot Syntax.
Probably more likeconnect(ui->m_pClientsocket, &QAbstractSocket:::errorOccurred, this, &Dialog:::displayError);