Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

12.7. invokeMethod()

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.

Example 12.16. src/reflection/invokemethod/autosaver.cpp

void AutoSaver::saveIfNecessary() {
    if (!QMetaObject::invokeMethod(parent(), "save")) {
        qWarning() << "AutoSaver: error invoking save() on parent";
    }
}


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint