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. QML Syntax check
Forum Updated to NodeBB v4.3 + New Features

QML Syntax check

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.7k 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.
  • K Offline
    K Offline
    kortus
    wrote on 16 Jul 2013, 07:29 last edited by
    #1

    Hello,

    I have searched the forum but found no result. We start to develop the GUI with QML and in this case
    a lot of syntax errors made by programmers. I use QtCreator 2.7.2 (Based on At 5.1.0). Normally a lot of syntax errors found by the editor or by Tools.QML/JS.Run Checks.

    But in the following case I can't found the error with the tools including the debugger
    @
    import QtQuick 2.0

    Rectangle {
    id: rectangle1
    width: 360
    height: 360

    MidRectangle {
    id: midrectangle1

    width: parent.width / 2
    height: parent.heightt / 2 // <-- syntax error should be height
    }

    MouseArea {
    anchors.fill: parent
    onClicked: {
    Qt.quit()
    }
    }
    }@

    MidRectangle is a simple Rectangle centered in the parent:

    @
    import QtQuick 2.0

    Rectangle {
    width: 50
    height: 50

    anchors.horizontalCenter: parent.horizontalCenter
    anchors.verticalCenter: parent.verticalCenter

    color: "#13caf3"
    border.color: "#ff0000"

    }
    @

    There is no runtime error, why? And the result of the program is complete different from the expected.
    How can I find such syntax error automatically? In the past I used QScript and there are checkSyntax() and evaluate() functions to find such errors.

    Thanks

    1 Reply Last reply
    0
    • C Offline
      C Offline
      chrisadams
      wrote on 17 Jul 2013, 01:36 last edited by
      #2

      The short answer is: that is not a syntax error.

      All property bindings are JavaScript expressions. JavaScript expressions can arbitrarily modify objects (add dynamic properties, instantiate new objects, and so forth) - and the halting problem states that until you run a bit of code, you cannot know with certainty what the outcome will be. So at build time, it's difficult to know whether the symbol "parent.heightt" will be resolvable at run time.

      (Well, of course, that's an oversimplification, since you can look for things which change the evaluation context (like eval() etc) and if none exist, you can assume that the runtime context "should be" identical to the context model that your tooling generates at build time - assuming that you have a full expression evaluator built into your tooling, of course).

      Now, there will be a runtime error (you should see something like "ReferenceError: parent.heightt not resolvable" at runtime, when the property bindings are initialized (evaluated for the first time)) which you could scrape for error detection.

      Alternatively, you could write a tool which parses all QML files and builds up a hash of static QML type information (type names and their property names), and then runs over your source tree and identifies any non-static property usages in other QML files. I think QtCreator could/should include something like this, if it does not already, as I agree that it's a common case which tooling should help solve (by warning / yellow squiggley at the very least).

      Cheers,
      Chris.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kortus
        wrote on 17 Jul 2013, 10:09 last edited by
        #3

        Thanks, syntax or not:-) I need a way to detect such errors.
        You are right, with

        @
        height: myValue
        @

        I get a ReferenceError: myValue is not defined message, which is very helpfull.
        But not for the line

        @
        height: parent.heightt
        @

        I see no reason to ignore the second one except a bug.

        Best
        Steffen

        1 Reply Last reply
        0

        1/3

        16 Jul 2013, 07:29

        • Login

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