QPlace
20th July 2007, 16:03
I have following test code:
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
ClientSocket client(&a);
client.connectToHost(QHostAddress::LocalHost, (quint16)12000,QTcpSocket::ReadWrite);
/* offensive part
QTextStream stream(stdin);
QString line;
do {
line = stream.readLine();
if (!line.isNull())
client.SendCommand(1, line);
} while (!line.isNull());
*/
return a.exec();
}
ClientSocket is derived from QTcpSocket. When "offensive part" is commented out everything works fine, i.e socket connects to the server etc. When "offensive part" is uncommented the main event loop is not started, QT event system is broken.
My question is: how to enable input from the console and also have socket signals processed correctly? I want to be able to do something similar to telnet, where the user types in the console and text is written to a socket for transmission. I understand that I can put socket in the separate thread, but I wonder if I miss some class (or functionality in classes that I use) that will allow me to do it in the main thread.
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
ClientSocket client(&a);
client.connectToHost(QHostAddress::LocalHost, (quint16)12000,QTcpSocket::ReadWrite);
/* offensive part
QTextStream stream(stdin);
QString line;
do {
line = stream.readLine();
if (!line.isNull())
client.SendCommand(1, line);
} while (!line.isNull());
*/
return a.exec();
}
ClientSocket is derived from QTcpSocket. When "offensive part" is commented out everything works fine, i.e socket connects to the server etc. When "offensive part" is uncommented the main event loop is not started, QT event system is broken.
My question is: how to enable input from the console and also have socket signals processed correctly? I want to be able to do something similar to telnet, where the user types in the console and text is written to a socket for transmission. I understand that I can put socket in the separate thread, but I wonder if I miss some class (or functionality in classes that I use) that will allow me to do it in the main thread.