I want to bind qt qml code to c++ functions and c++ source file. How can I run c++ function directly from qml code for example button onClick event? And how can I call a function from a c++ source file in qml for example onClick event? plz explain more and more! I'm beginner.
Asked
Active
Viewed 212 times
-4
-
Please read [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) – Ilyes Jan 27 '17 at 08:19
-
1For instance: http://stackoverflow.com/questions/9500280/access-c-function-from-qml – KimKulling Jan 27 '17 at 08:20
-
1**This Question Doesnt Need Code Example** – Addr3ss Jan 27 '17 at 08:23
2 Answers
2
There are several options.
A C++ class that can be instantiated from QML, see Access C++ function from QML as KimKulling pointed out in a comment
A C++ class instantiated in C++ and exposed to the QML engine via
QQmlContext::setContextProperty()
, see my answer on I have multiple qml Files that get pushed via StackView. How do I connect them to C++ for that techniqueA C++ class instantiated once in C++ and used as a "QML Singleton" via
qmlRegisterSingleton()

Community
- 1
- 1

Kevin Krammer
- 5,159
- 2
- 9
- 22
-1
You should read the official documentation on signals and slots.
Basically, you are assigning a C++ function to a signal. If the signal is catched, it calls the function.

SAlex
- 361
- 2
- 10