I'm doing an if (waitForConnected(-1)) after the connectToHost if that wat you mean?
Should I add anything else here?
(I'm new to Qt and Socket-programming)
From the read_data() function:
tcpSocket->abort();
tcpSocket->connectToHost(hostLineEdit->text(),
portLineEdit->text().toInt());
cout << ("after connectToHost\n");
if(tcpSocket->waitForConnected(-1))
{
cout <<"wait for connected loop\n";
if(tcpSocket->canReadLine())
{
mystring=tcpSocket->readLine();
qDebug() << "READ" << mystring;
cout <<"canReadLine loop after readLine\n";
}
statusLabel->setText(mystring);
getFortuneButton->setEnabled(false);
}
tcpSocket->abort();
tcpSocket->connectToHost(hostLineEdit->text(),
portLineEdit->text().toInt());
cout << ("after connectToHost\n");
if(tcpSocket->waitForConnected(-1))
{
cout <<"wait for connected loop\n";
if(tcpSocket->canReadLine())
{
mystring=tcpSocket->readLine();
qDebug() << "READ" << mystring;
cout <<"canReadLine loop after readLine\n";
}
statusLabel->setText(mystring);
getFortuneButton->setEnabled(false);
}
To copy to clipboard, switch view to plain text mode
Bookmarks