I'm using QTcpSocket
for this program.
void MainWindow::connectFunction()
{
socket->connectToHost(ip, port);
if(socket->waitForConnected(2000))
{
QTime time = QTime().currentTime();
ui->textBrowser->append('[' + time.toString("h:m") + "] Connection successful.");
}
else
{
QTime time = QTime().currentTime();
ui->textBrowser->append('[' + time.toString("h:m") + "] Connection failed. Retrying...");
connectFunction();
}
}
I attempt to connect to the server with ui->connectToHost(ip, port)
. If the connection fails, I call connectFunction()
again to restart the connecting process. It should do this until the connection is successful. The problem arises when I call connectFunction()
. This crashes the program, and I don't know why. Any help would be appreciated.