QML invokeMethod无法找到父方法

时间:2018-01-11 15:38:54

标签: qt file qml scene defined

Main.qml

GameWindow {
    id: gameWindow
    menuBarVPlayEnabled: false

    activeScene: scene
    SoundEffectVPlay {id:reelSound; source:"../assets/snd/reels.wav";loops: SoundEffect.Infinite}
    SoundEffectVPlay {id:creditInSound; source:"../assets/snd/addcredit.wav";}
    SoundEffectVPlay {id:betInSound; source:"../assets/snd/betincrease.wav";}
    SoundEffectVPlay {id:winGolgeSound; source:"../assets/snd/cheering.wav";}

    screenWidth: 800
    screenHeight: 600

    Scene {
        id: scene


        width: 480
        height: 320

        // properties for the game
        property int creditAmount : 1 // amount to bet per line  

        ... etc
}
    MyFunctions {
        id: myFunctions
    }
}

MyFunctions.qml

import VPlay 2.0
import QtQuick 2.0

Item {
    id:myFunctions

    anchors.fill: parent

    //property GameWindow gameWindow

    function setCreditFunc(msg) {
        console.log("Got message:", msg)
        scene.creditAmount = msg
        return "some return value"
    }
}

的main.cpp

QQmlEngine engine;
QQmlComponent component(&engine, "MyFunctions.qml");
QObject *object = component.create();

QVariant returnedValue;
QVariant msg = 30;
// I try to reach function
QMetaObject::invokeMethod(object, "setCreditFunc",
        Q_RETURN_ARG(QVariant, returnedValue),
        Q_ARG(QVariant, msg));   

我想从MyFunctions.qml到达Main.qml属性 我收到一个错误:MyFunctions.qml:13:ReferenceError:未定义场景

0 个答案:

没有答案