Calling static function through QMetaObject
Is there a way to invoke a static method of a class without supplying an object to the invokeMethod(...) of the QMetaObject?
Why do you want to use invokeMethod() to call a static method?
@jsulm Well, because the method that I would like to invoke would not require an instance and therefore a static method is what I prefer. Is there any way to invoke a static method without an instance?
The QMetaObkect::method(index) function also returns me the invokable static methods.
Are we talking normal static functions?
so you just call it like
@mrjj Yes, a standard C++ static member function which is defined with Q_INVOKABLE. I will not only know at runtime which staticMetaObject I have to call this function. Therefore I can not use ClassName::static_method().
Ok, so this is also regarding calling / make available to QML ? / scripting ?
@mrjj Not necessarily, I just want sometimes to call a static function of different static meta objects without first using the newInstance to create an instance for performance reasons.
This is not possible with current API. Take a look at the generated
moc_*.cppfile. The methods called via meta objects are always routed through
YourClass::qt_static_metacalland it always takes an object pointer.
@Chris-Kawa Thanks for the information provided. Then I need to re-design my implementation accordingly to this limitation.