Ok. simple example tcp connect to 80 port.
void MainWindow::on_pushButton_clicked()
{
ui->label->setText("");
connect(mysocket,SIGNAL(connected()),this,SLOT(on_connected()));
mysocket->connectToHost(ui->lineEdit->text(), 80);
}
{
ui
->label
->setText
("Not connected " + QString::number(socketError
));
}
void MainWindow::on_connected()
{
ui->label->setText("It's ok. Connected");
mysocket->disconnectFromHost();
}
void MainWindow::on_pushButton_clicked()
{
ui->label->setText("");
connect(mysocket,SIGNAL(connected()),this,SLOT(on_connected()));
connect(mysocket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(on_error(QAbstractSocket::SocketError)));
mysocket->connectToHost(ui->lineEdit->text(), 80);
}
void MainWindow::on_error(QAbstractSocket::SocketError socketError)
{
ui->label->setText("Not connected " + QString::number(socketError));
}
void MainWindow::on_connected()
{
ui->label->setText("It's ok. Connected");
mysocket->disconnectFromHost();
}
To copy to clipboard, switch view to plain text mode
Bookmarks