Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Qt’s capability to connect signals to slots requires a mechanism to indirectly call the slots in a type-safe way, by name. When a slot is called, it is actually done by invokeMethod(). Example 12.16 shows how it accepts a string for the method name. In addition to slots, regular methods marked Q_INVOKABLE can be invoked indirectly this way.
void AutoSaver::saveIfNecessary() {
if (!QMetaObject::invokeMethod(parent(), "save")) {
qWarning() << "AutoSaver: error invoking save() on parent";
}
} |