qtnetwork-programmingqt4qsslsocketqiodevice

Difference between QSocketNotifier::activated and QIODevice::readyRead


I create a new Read QSocketNotifier (QSocketNotifier::Read) and I install it on a QSslSocket. What is the QSslSocket signal that is emitted when activated signal is emitted from QSocketNotifier?

Is there any difference between the activated signal emitted by a QSocketNotifier which is installed on a QSslSocket and QIODevice::readyRead signal emitted by a QSslSocket?


Solution

  • If the QSocketNotifier is watching a QIODevice, then there is no functional difference between QIODevice::readyRead() and QSocketNotifier::activated(QSocketNotifier::Read). For that reason, you don't need a QSocketNotifier if you're only using QIODevice objects.

    The main use of QSocketNotifier is to monitor a socket (or any other file descriptor) that you opened through a low-level API. You may pass it a file descriptor that is not associated to another QObject (such as a file opened through std::ifstream) and it will fire a activated() signal when you may read from your file descriptor, which is useful since a generic file descriptor won't fire Qt signals by itself.