[SOLVED] connect to the server message
-
@
bool boo = connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
if ( !boo )
{
qDebug() << "cannot connect first signal " << endl;
}
boo = connect(socket, SIGNAL(connected()), this, SLOT(connected()));
if ( !boo )
{
qDebug() << "cannot connect second signal " << endl;
}if ( socket->connectToHost(serverAddress, 4200) == QAbstractSocket::ConnectedState ) { qDebug() << "we are connected ;-) " << endl; }
@
The states are given "here":http://doc.qt.nokia.com/4.7/qabstractsocket.html#SocketState-enum
Max. 15 lines to read. -
I am getting an error with this code. error: no match for 'operator==' in '((MainWindow*)this)->MainWindow::socket->QTcpSocket::<anonymous>.QAbstractSocket::connectToHost(((const QString&)((const QString*)(& serverAddress))), 4200, QFlagsQIODevice::OpenModeFlag((QIODevice::OpenModeFlag)3u)) == (QAbstractSocket::SocketState)3u'
@if ( socket->connectToHost(serverAddress, 4200) == QAbstractSocket::ConnectedState )@
-
Read "QAbstractSocket::connectToHost":http://doc.qt.nokia.com/latest/qabstractsocket.html#connectToHost and then read
"QAbstractSocket::waitForConnected":http://doc.qt.nokia.com/latest/qabstractsocket.html#waitForConnected.Just begin reading the documentation of classes you are trying to use. Every class has a "Detailed Description" section which is read in a few minutes and provides all the information needed to use this class - including related information and examples.
-
Lukas is completely right. Start to read the documentation. Both of us have pointed you to the right docs. Reading them would have been much faster for you.
[Edit] Part eliminated, was still wrong
-
thank you Lukas Geyer for the links. I solved this issue.
-
[quote author="koahnig" date="1313655049"]Lukas is completely right. Start to read the documentation. Both of us have pointed you to the right docs. Reading them would have been much faster for you.
Yes, you are right. The source I have provided in a hurry cannot compile.
It should probably more look like this.
@
socket->connectToHost(serverAddress, 4200);
if ( socket->state() == QAbstractSocket::ConnectedState )
{
qDebug() << "we are connected ;-) " << endl;
}
@However, this is not tested and just typed out of memory. All the links provided shall give the rest. [/quote]
The snippet is wrong. You need either to return to the event loop or use waitForConnected.
-
@peppe
Yes, now I see it. Was puzzled that there was no return value, but did not follow through.
Sorry for causing the confusion. It is not always the best to bridge recompilation time with giving advises. :-(
Sorry again. -
[quote author="kalster" date="1313655101"]thank you Lukas Geyer for the links. I solved this issue.[/quote]
You're welcome.
Beeing a developer sometimes means just to sit there and read documentation. I know this is boring most of the time but this is what I had to learn the hard way and I guess this is what we all had to learn.
The good thing with Qt is that its documentation is a prime example how it has to be done and it can be clearly stated as a reference when it comes to docmentation quality.
And everyone how hasn't had to read and study datasheets for MCUs developed and documented somewhere in a Taiwanese backyard, hundreds of pages long, half of the information missing and half of the information wrong should count oneself lucky anyway :-)
-
yes Lukas, i should have read the documents earlier. the problem i had was with the documents statements. It was taken me a while to read the documents and understanding the statements. hopefully, i don't have problems with the documents in the future.
-
If there are any basic questions which prevent you from understanding most of the documentation feel free to ask. That's way better than having tons of specific questions and stumbling from one problem to another.