【问题标题】:Loop on object property (QML)对象属性循环 (QML)
【发布时间】:2017-07-26 08:15:30
【问题描述】:

当我使用以下 QML 文件时,Qt 在运行时报错:

import QtQuick 2.7
import QtQuick.Controls 2.0

Rectangle
{
    color: palette.grey

    property var spotButtonFunctions :
    {
        'EditViewTool' : function() {switchToEditViewToolButton.source = "../View/Icons/icon_game.png";},
        'SelectTool'   : function() {switchToSelectToolButton.source = "../View/Icons/icon_game.png";}
    }

    property var greyButtonFunctions :
    {
        'EditViewTool' : function() {switchToEditViewToolButton.source = "../View/Icons/icon_settings.png";},
        'SelectTool'   : function() {switchToSelectToolButton.source = "../View/Icons/icon_info.png";}
    }

    // View update slots.
    function onNotifyCurrentToolSignal(currentToolName)
    {
        // Grey all tool buttons.
        for (x in greyButtonFunctions)
            greyButtonFunctions[x]();

        // Spot the current tool button.
        if (currentToolName !== "")
            spotButtonFunctions[currentToolName]();
    }
}

错误信息与for (x in greyButtonFunctions)行有关:

错误:无法将 QString 分配给 double

有什么想法吗?

【问题讨论】:

    标签: qt qml qtquick2 qtquickcontrols2


    【解决方案1】:

    您正在分配给Item 的x property。

    如果你想要一个名为 x 的局部变量,你必须这样做 for (var x in greyButtonFunctions)

    【讨论】:

      猜你喜欢
      • 2012-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-26
      • 2021-11-20
      • 2013-11-09
      • 2016-09-09
      相关资源
      最近更新 更多