Hi
When using sockets with signals and slots on the mainthread and the use a QTextStream for interpreting a text protocol from the network (but the question is rather generic so I guess it may apply to other kinds of streams like XmlStream and DataStream as well):
1) When should I create the stream object? Not during each readyRead() signal I assume since this would create a new object for each piece of data (I did see an example where this was used)? Perhaps during connect() and destroy it when disconnect() arrives?
2) When the QTextStream object in created, how should I read the data? Should I wait for the readyRead() signal and then call stream.readLine() for reading a line? I would think this is a blocking operation and therefore would block the entire gui-thread if there are no complete line available at the time of the readyRead() signal emission. Or perhaps the streams got some fancy features for handling just this? I am sure I cant be the first to wonder about this...
I would highly appreciate some help on this. I am used to (from Java) just use the blocking operation and throw everything into a new thread, but since thread synchronization is a bitch and you in QT got this sweet signal to let you know when there is more data...
Thanks!!
Bookmarks