Question

I have been making my C++ functions callable from Qml by following the approach given in Qt documentation.

This require one of these conditions to be fulfilled :

  1. Make the C++ function public and Q_INVOKABLE or
  2. Make the C++ function a public slot

This sometimes is not in sync with my class design. As in, the function which I want to be callable from Qml, is private according to my class design.

Q1. Can I make a function visible to Qml and still keep it private ?

Q2. Is it my design flaw to expect this kind of behavior ?

Was it helpful?

Solution

Well, if you do something private by design you consider that it's something to be used only within a class. Now you are now asking actually is how can I workaround my design. Obvious answer is - you can make a public wrapper in a class which will invoke your private method and publish this public wrapper into QML, but I would suggest to review design if you face such situation.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top