-4

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.

Addr3ss
  • 21
  • 4

2 Answers2

2

There are several options.

  1. A C++ class that can be instantiated from QML, see Access C++ function from QML as KimKulling pointed out in a comment

  2. 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 technique

  3. A 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