I found the QAbstractSocket::bind method but it doesn't seem to work
void ConnectionHandler::connectToServer() {
this->socket->connectToHost(this->ip, this->port);
if (!this->socket->waitForConnected()) {
this->socket->close();
this->errorMsg = this->socket->errorString();
}
qDebug() << this->socket->localPort();
}
void ConnectionHandler::connectToServer() {
this->socket->bind(QHostAddress::LocalHost, 2000);
this->socket->connectToHost(this->ip, this->port);
if (!this->socket->waitForConnected()) {
this->socket->close();
this->errorMsg = this->socket->errorString();
}
qDebug() << this->socket->localPort();
}
To copy to clipboard, switch view to plain text mode
The output I get is again a random port and not 2000!?
Bookmarks