Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Help with error. Renamed icon failing upon being referenced.



  • I recently renamed an custom element. The element itself seems fairly straight forward and I do not believe it is causing the problem but here's it's definition:

    ThemedIcon
    {
      id: _helpIcon //renamed from "help"
      imageSource: "qrc:/Assets/Image/information.svg"
      height: 30
      checked: false
      width: height
      anchors
      {
        top: parent.top
        topMargin: 20
      }
    }
    

    somewhere on down the line this icon is being referenced:

    property bool helpEnabled: _helpIcon.checked && helpText !==  ""
    

    and it has the following comment next to it:
    //unexcusable abuse of qml tree with reusable specific component //yet you didn't fix it...

    So as I said I renamed the elment from "help" to "_helpIcon" and for some reason that broke the above property:

    ReferenceError: _helpIcon is not defined
    

    So I am new to QML and I have no idea what the comment is referring to and I don't see why changing this ThemedIcon's name would break anything. Any ideas what's happening here? Keep in mind the comment was not left by anyone in this office and the custom element was not built by anyone in this office. Otherwise I would just contact them and ask them lol


  • Moderators

    @Circuits

    you have to show some more of that file.

    Currently it should work, I explicitly checked it with _ as first character. But as a rule of thumb it would be good to start id's with a small letter and no capitals or special chars

    What version of Qt and QtQuick(import) do you use



  • @J-Hilk Which file would you like to see more of? I figured out that the ThemedIcon is being created in a file which is holding another custom component:

    Component
    {
      id addNew
      
      NewFlow
      {
        id: _addNewFlow
        anchors.fill: parent
      {
    {
    

    which is then holding another compoenent of it's own:

    SettingsValueContainer
    {
    ...
    }
    

    which is the script housing the property. Here is what I also know. If I simply change the name back from _helpIcon to help it works again. This is a bit concerning because I have been starting all of my compoenent and element id's with an _

    EDIT: I think I figured out the problem but I am not sure what the convention is for how this should have been done. It would seem that there are multiple ThemedIcon's fighting over who owns this property or who this property is referencing. One exists within a file called ImplementSettingScreen:

    ThemedIcon
    {
      id: help
      imageSource: "qrc:/Assets/Images/information.svg"
      height: 30
      checked: false
      width: height
      anchors
      {
        top: parent.top
        topMargin: 20
      }
    }
    

    and again in the file i mentioned earlier called GuidanceSettingScreen:

    ThemedIcon
    {
      id: help
      imageSource: "qrc:/Assets/Images/information.svg"
      height: 30
      checked: false
      width: height
      anchors
      {
        right: parent.right
        top: parent.top
        rightMargin: 20
        topMargin: 20
      }
    }
    

    So when they are both named "help" then np but as soon as I change the name of one or the other (but not both) then they it's like the machine finally recognizes there was a conflict...

    how could this property possibly know which themedIcon called "help" it is suppose to be basing it's logic off of?

    EDIT 2

    There are many (many) more ThemedIcon's called "help". Now I am starting to understand the comment I think.


Log in to reply