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.
Make a private C++ function visible to Qml
-
11-04-2022 - |
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 :
- Make the C++ function
public
andQ_INVOKABLE
or - 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 ?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow