我们可以在QML文件中声明全局变量吗? [英] Can we declare global variable in QML file?

查看:326
本文介绍了我们可以在QML文件中声明全局变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对以下代码做一些similer:

I want to do something similer to following code:

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

    function increment() // JavaScript function
    {
        globalforJs++;
    }
    ....
QML Code

我们可以吗?在 QML文件中有全局变量并从JavaScript函数访问它?

Can we have global variable in QML file and access it from the JavaScript function?

推荐答案

尝试 property int globalForJs:10;

如果你想要一个可以采用任何类型的变量:

If you want a variable that can take any type:

property var globalForJs:10

在QML 2之前,使用变种关键字而不是 var

Prior to QML 2, use the variant keyword instead of var.

这篇关于我们可以在QML文件中声明全局变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆