Can we declare global variable in QML file?

前端 未结 3 2049
北海茫月
北海茫月 2021-01-03 22:56

I want to do something similer to following code:

//test.qml
import QtQuick 1.0
Item 
{
    var globalforJs =10;

    function increment() // JavaScript fu         


        
3条回答
  •  情歌与酒
    2021-01-03 23:27

    the thing which you want to make global should be done like in this example

    property variant name:"john"//i want this to be global
    onCreationCompleted(){
    Qt.name = name
    }
    

    whereever you want to use the name property use like Qt.name instead of just name.this also applicable for any ids of controls

提交回复
热议问题