PDA

View Full Version : QtSocket readyRead and exception



joseluis
16th June 2015, 14:16
Hi.

If you are processing a readyRead slot and new information is received, you will not be inform about it. It looks logical...

http://stackoverflow.com/questions/16023533/how-to-make-sure-that-readyread-signals-from-qtcpsocket-cant-be-missed


Is it possible that an exception thrown inside of readyRead slot, and captured on QApplication::notify the socket thinks my application continues inside readyRead slot?

To solve it, I only need to add a try catch on readyRead slot.

It looks confusing and not enough documented.


I suppose, that Qt cannot manage the situation because the slot could be thrown to a different thread. Is that right?



kind regards

yeye_olive
16th June 2015, 15:06
Hi.

If you are processing a readyRead slot and new information is received, you will not be inform about it. It looks logical...

http://stackoverflow.com/questions/16023533/how-to-make-sure-that-readyread-signals-from-qtcpsocket-cant-be-missed
Are you certain that the problem mentioned in the thread you linked to actually exists? Have you run into it? I have always assumed that all I had to do was read all the available data before exiting readyRead(), and I have never faced such an issue doing so.


Is it possible that an exception thrown inside of readyRead slot, and captured on QApplication::notify the socket thinks my application continues inside readyRead slot?

To solve it, I only need to add a try catch on readyRead slot.

It looks confusing and not enough documented.
You must not let an exception propagate outside a slot whose execution was triggered by Qt's signals and slots mechanism; see http://doc.qt.io/qt-5/exceptionsafety.html#signals-and-slots. Maybe the documentation does not put enough stress on this limitation.


I suppose, that Qt cannot manage the situation because the slot could be thrown to a different thread. Is that right?
I am not aware of the reasons for this limitation, but supporting exceptions would raise--no pun intended--some non-trivial questions. E.g would the exception propagate to the caller for a direct connection, and outside the event loop executing the slot for a queued connection? This would break the locality of the component model offered by signals and slots. Besides, Qt's code would need to be exception-safe, which would probably significantly hurt performance.