C++ class exposed to QML error in fashion TypeError: Property '…' of object is not a function

后端 未结 3 1978
北荒
北荒 2021-01-18 05:37

I\'ve successfully exposed a C++ class to QML. It is registered and found in Qt Creator. It\'s purpose is to connect to a database, as shown in following code:



        
3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-18 05:57

    You have this error because you have declared the property isConnected in C++ but you're calling it from QML in the wrong way: uePosDatabase.isConnected is the correct way, not uePosDatabase.isConnected().

    If you want to call the function isConnected() you should change its name to differate it from the property, like getIsConnected(). Given your property declaration, you neither need to call this function directly nor you need to make it callable from QML with the Q_INVOKABLE macro.

提交回复
热议问题