-
Notifications
You must be signed in to change notification settings - Fork 0
4.02
Tino: Let's change the title to: Accessing C++ from QML and vice versa. We should emphasise already in the title that accessing QML from C++ is possible but not recommended
Explanation of the contents of a topic page @ Topic reference page
Objective: Learn how to make C++ code accessible from QML and how QML can be accessed from C++
Tino: This session will actually made 4.05 obsolete. We need to explain (again) that QIbject properties, enums, signals, slots, and invokable are accessible. I would not wait until 4.05. Let's then use just the simple setContextProperty() function here and leave the type registrations to the next session. Perhaps it should be emphasised though that if the object is not going to be used in C++ at all, it's better to register it as a type, which is explained in the next session. Or alternatively, we can explain it at the beginning of the next session.
Tino: The best way to access QML objects from C++ is to use the root object and QObject findChild("myObjectName"). This means we should give accessible QML objects a name (objectName) property. finfChild is rather heavy, so this is one reason not to do this and it should be emphasised that C++ provides stuff to QML and not vice versa. Examples of accessing the JS methods are required. Both using a signal/slot connection and QMetaObject::invokeMethod().
- What is a meta-object?
- What is object introspection?*
- How to make QObject members accessible from QML?
- What is Q_INVOKABLE?
- What is Q_GADGET?
- What is NOTIFY in the context of properties?
- How QML objects can be accessed from C++?
- How QML object JavaScript methods are accessible from C++?