Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Any tool to flag QML file warnings?
Forum Updated to NodeBB v4.3 + New Features

Any tool to flag QML file warnings?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
10 Posts 3 Posters 795 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Tom assoT Offline
    Tom assoT Offline
    Tom asso
    wrote on last edited by Tom asso
    #1

    I’m working with Qt 6.7.2. I’ve just spent several hours tracking down a bug in my qml file. The problem was that a QML Text item specified an id that matched the name of a standard FileDialog property, which caused an error when processing the FileDialog user input. The main.qml was 400+ lines long - here is a brief summary:

    Window {
    
      [...]
      Text {
        id: selectedFile
        [...]
      }
    
    
      FileDialog {
        id: fileDialog
        [...]
        onAccepted: {
          // Expect selectedFile to be url of the last user-selected file
          console.log('accepted ' + selectedFile);
        }
      }
    

    I expected the FileDialog’s selectedFile property would contain the url of the latest user-selected file, e.g. expected the console.log message to look something like this:

    accepted file:///home/anon/mb-test-data/Extravert.grd
    

    But instead I see:

    accepted QQuickText(0x565143b11010, "selectedFile")
    

    I.e. the Text item with id selectedFile 'shadows' the FileDialog's selectedFile property.
    I spent hours debugging this problem. The bug appears obvious in my terse summary of main.qml - but in reality main.qml is 450 lines long! Is there a Qt 6.7 tool that would alert me to this kind of problem? QtCreator did not show any warning or error associated with selectedFile.

    Thanks!

    1 Reply Last reply
    0
    • Axel SpoerlA Axel Spoerl

      This is a behavioural bug. A QML Type is logged, while its baseUrl or text property was expected. Probably you wanted to write something like this:

      console.log('accepted ' + selectedFile.baseUrl)
      

      How should creator know that?

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #4

      @Axel-Spoerl What OP wrote is what OP wanted to write. FileDialog has a selectedFile property.

      The issue is the weird shadowing of property by an id in an outer scope.

      @Tom-asso I'd report it as a bug. It's weird that this is happening. If it can't be fixed due to some limitation, it should at least output a qmllint warning.

      Tom assoT 1 Reply Last reply
      2
      • Tom assoT Offline
        Tom assoT Offline
        Tom asso
        wrote on last edited by Tom asso
        #2

        qmllint looked promising, but alas did not flag this bug either.

        1 Reply Last reply
        0
        • Axel SpoerlA Offline
          Axel SpoerlA Offline
          Axel Spoerl
          Moderators
          wrote on last edited by
          #3

          This is a behavioural bug. A QML Type is logged, while its baseUrl or text property was expected. Probably you wanted to write something like this:

          console.log('accepted ' + selectedFile.baseUrl)
          

          How should creator know that?

          Software Engineer
          The Qt Company, Oslo

          GrecKoG 1 Reply Last reply
          0
          • Axel SpoerlA Axel Spoerl

            This is a behavioural bug. A QML Type is logged, while its baseUrl or text property was expected. Probably you wanted to write something like this:

            console.log('accepted ' + selectedFile.baseUrl)
            

            How should creator know that?

            GrecKoG Offline
            GrecKoG Offline
            GrecKo
            Qt Champions 2018
            wrote on last edited by
            #4

            @Axel-Spoerl What OP wrote is what OP wanted to write. FileDialog has a selectedFile property.

            The issue is the weird shadowing of property by an id in an outer scope.

            @Tom-asso I'd report it as a bug. It's weird that this is happening. If it can't be fixed due to some limitation, it should at least output a qmllint warning.

            Tom assoT 1 Reply Last reply
            2
            • GrecKoG GrecKo

              @Axel-Spoerl What OP wrote is what OP wanted to write. FileDialog has a selectedFile property.

              The issue is the weird shadowing of property by an id in an outer scope.

              @Tom-asso I'd report it as a bug. It's weird that this is happening. If it can't be fixed due to some limitation, it should at least output a qmllint warning.

              Tom assoT Offline
              Tom assoT Offline
              Tom asso
              wrote on last edited by
              #5

              @GrecKo - Yes, you are right. I will report it as a bug.
              Thanks guys!

              1 Reply Last reply
              0
              • Tom assoT Tom asso has marked this topic as solved on
              • Axel SpoerlA Offline
                Axel SpoerlA Offline
                Axel Spoerl
                Moderators
                wrote on last edited by
                #6

                I obviously overlooked this one.
                The answer is no, there isn’t such an ambiguity warning. That said, an id from an outer scope would always shadow properties, because the outer scope is imported after the object has been instantiated. That’s not a bug. But you could add a suggestion to warn about such cases.

                Software Engineer
                The Qt Company, Oslo

                1 Reply Last reply
                1
                • GrecKoG Offline
                  GrecKoG Offline
                  GrecKo
                  Qt Champions 2018
                  wrote on last edited by
                  #7

                  @Tom-asso When you do, could you post the link to the bugreport here?

                  Tom assoT 1 Reply Last reply
                  1
                  • GrecKoG GrecKo

                    @Tom-asso When you do, could you post the link to the bugreport here?

                    Tom assoT Offline
                    Tom assoT Offline
                    Tom asso
                    wrote on last edited by Tom asso
                    #8

                    @GrecKo , @Axel-Spoerl - I see about 20 projects to select from at the bug tracker - which one is appropriate in this case? Thanks

                    1 Reply Last reply
                    0
                    • Axel SpoerlA Offline
                      Axel SpoerlA Offline
                      Axel Spoerl
                      Moderators
                      wrote on last edited by
                      #9

                      Project is QTBUG.
                      Issue type should be Suggestion.

                      Software Engineer
                      The Qt Company, Oslo

                      1 Reply Last reply
                      1
                      • Tom assoT Offline
                        Tom assoT Offline
                        Tom asso
                        wrote on last edited by
                        #10

                        I submitted a bug/suggestion report

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved