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

后端 未结 3 1975
北荒
北荒 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:51

    You must first create the object you want in QML code and then use the function:

    your QML Code:

    import QtQuick 2.0
    import QSqlDatabase 1.0
    
    Rectangle {
        id: ueMenuButton
    
        QSqlDatabase {
            id: uePosDatabase
        }
    .
    .
    .
        MouseArea
        {
            id: ueClickArea
            antialiasing: true
            anchors.fill: parent
    
            onClicked: {
                console.log(uePosDatabase.isConnected())
            }
        }
    }
    

提交回复
热议问题