QML访问C++成员函数报错:TypeError: Property 'showHome' of object [object Object] is not a function

问题:在成员函数showHome()前面加了Q_INVOKABLE,还是报错TypeError: Property 'showHome' of object [object Object] is not a function

原因:在QML中直接用类名调用了成员函数showHome()。

import LoginClass.module 1.0

解决前代码片段:

 1 Button {
 2   ......
 3   onClicked: {
 4     LoginClass.showHome()
 5    }
 6 }

解决后代码片段:

 1 Button {
 2   ......
 3   onClicked: {
 4     login.showHome()
 5    }
 6 }
 7 
 8 LoginClass{
 9     id: login
10 }

 

posted @ 2020-04-28 17:20  绿筱  阅读(4000)  评论(2)    收藏  举报