4199Fermer4201
deleted2Le 28/08/2019 à 23:30
Dans la doc de Qt, je lis ça :
int QObject::receivers(const char *signal) const

Returns the number of receivers connected to the signal.

Since both slots and signals can be used as receivers for signals, and the same connections can be made many times, the number of receivers is the same as the number of connections made from this signal.

When calling this function, you can use the SIGNAL() macro to pass a specific signal:

if (receivers(SIGNAL(valueChanged(QByteArray))) > 0) {
    QByteArray data;
    get_the_value(&data);       // expensive operation
    emit valueChanged(data);
}

Warning: This function violates the object-oriented principle of modularity. However, it might be useful when you need to perform expensive initialization only if something is connected to a signal.
Mais qu'est-ce que le principe de modularité en POO, et qu'est-ce que ça fout dans ce contexte ? J'ai jamais lu ça encore...