Syntax error in "Creating a Qt Quick Application" example



  • Hi,

    First the environment. I'm using fedora 15 obtained directly from the fedora site. I'm also using

    qt-creator-linux-x86-opensource-2.4.1.bin

    obtained directly from Nokia/Qt and which installed without any errors or warnings. It would be useful to have a printed copy of the tutorial "Creating a Qt Quick Application" (which is supplied with the package) to hand as it will clarify the following text.

    I'm trying to teach myself how to use Qt Creator and have tried to work through the tutorial mentioned above. I got as far as the top of printed page 7 and successfully completed the code change required in step "8. Edit Mouse Area properties:". At this point in the code editor line 29 contained the word "Image" which was underlined in red.

    On printed page 7 we also have step "9. In the Navigator pane, ...". To get to this pane I needed to switch to the Design Mode. On doing so I found an error dialog superimposed on the centre of the "workpiece" window. This contained the text "Syntax error (29:5)" beneath which was a link entitled "Go to error" which was underlined in blue. On clicking this link I was taken into the code editor, to line 29 where, as stated previously, the word "Image" was red underlined.

    Has anyone else come across this behaviour ?

    Does anyone know what change should be made to this line/code in order to cure the error ?

    Thanks in advance for any help that may be offered.

    Best regards,

    Stuart

    [Edit: Split from a different and (I believe) unrelated thread. Please start new threads for new topics. mlong]


  • Moderators

    I believe "this":http://doc.qt.nokia.com/qtcreator-2.4/creator-qml-application.html is a link to the example under discussion.


  • Moderators

    Can you please provide a cut-and-paste of your code as it appears in your editor, so that it can be compared against the code in the example? Thanks!



  • Hi mlong,

    Thanks for the reply. This is the code starting at
    line 10 before it is edited.
    @
    MouseArea {
    id: mousearea1
    onClicked: {
    Qt.quit();
    }
    @
    This is the code starting at line 10 after it is edited.
    @
    MouseArea {
    anchors.fill: parent
    onClicked: page.state = ''
    }
    @
    This morning I am getting a different error. In Design Mode
    I'm now getting the following error.

    Unexpected token '}' (35:1)
    Go to error

    Here is the complete xml file as it exists at this point in
    the tutorial.
    @
    // import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
    import QtQuick 1.1
    import QtQuick 1.0

    Rectangle {
    id: page
    width: 360
    height: 360
    color: "#343434"
    MouseArea {
    anchors.fill: parent
    onClicked: page.state = ''
    }

        Image {
            id: icon
            x: 10
            y: 20
            source: "qtcreator.png"
        }
    
        Rectangle {
            id: topLeftRect
            width: 64
            height: 64
            color: "#00000000"
            radius: 6
            anchors.left: parent.left
            anchors.leftMargin: 10
            anchors.top: parent.top
            anchors.topMargin: 20
            border.color: "#000000"
        }
    }
    

    }
    @
    As can be clearly seen, the only thing that can be seen on
    line 35 is a closing right brace.

    I have no idea why I'm getting a different error today
    compared to my original posting. I have followed through
    the tutorial in exactly(!) the same way this morning as I
    have on the several attempts prior to my original posting.

    I really hope this information proves helpful.

    Best regards,

    Stuart

    P.S. I've just checked this posting using the Preview button and have noticed that the preview is not maintaining the indentation. I hope this will not be too much of a problem as I don't know how to fix this. Sorry!

    [Edit] code wrappings added, koahnig


  • Moderators

    @Stuart
    You should use "code wrapping":http://qt-project.org/wiki/ForumHelp#e3f82045ad0f480d3fb9e0ac2d58fb01 . as you have already recognized the code with look strange otherwise.


  • Moderators

    I suspect that you have a mismatched pair of curly braces. make sure that you have an equal number of both and that they are in the right place.

    In your first snippet, you have a missing closing brace. I suspect that in your code it wasn't actually missing, but rather a lot further down the page than it should have been, thus making a lot of things fall within the scope of the mouse area that shouldn't. This is the cause of the syntax error.

    Then, in your second, you've edited the clicked action and removed an opening curly brace. This is leaving an orphaned closing brace on the last line.


  • Moderators

    Also, to help track down the situation you have in your first snippet, when viewing the code in creator use the auto indenter to help find the mismatch by using Ctrl-A to highlight everything, then using Ctrl-I to auto indent. Anything that isn't indented like you expect is a hint to where your mismatch starts.



  • Hi mlong,

    Thanks for the further help. You were correct about the uneven number of braces. Commenting out the very last one cured the error. I also moved the second last one to column one. That was just cosmetic. I doubt it helped in curing the error.

    I've also just had a look at my second posting, the one I posted this morning. It's now displaying with all the correct indentation. It even has line numbers, although I didn't include those. Any idea how that happened ?

    Lastly, I've just read through a code wrapping thread at qt-project.org. It can be found here.

    https://qt-project.org/forums/viewthread/15685

    It mentions using [code] but not [/code]. Maybe the latter is implied ? I'm really not up to speed on markup languages. Sorry!

    Anyway, I'll now get on and try to finish that tutorial. Thanks again for the help.

    Best regards,

    Stuart



  • Hi mlong,

    In my previous posting, that first "@" should be "[ c o d e ]" whilst the second "@" should be "[ / c o d e ]", without the spaces. I'll get the hang of this forum yet! ;-)

    Stuart


  • Moderators

    The code tagging is very simple. Wrapping your code blocks with "@" tags (without the quotes, of course) gives you pretty, formatted, syntax-highlighted, numbered code.

    "@"
    void foo(int bar) {

    baz();

    }
    "@"

    becomes

    @
    void foo(int bar) {
    baz();
    }
    @



  • Hi mlong,

    That code tagging is very simple. I'll print out your last reply and keep it for future reference.

    Thanks very much.

    Stuart


  • Moderators

    [quote author="stuarte9" date="1332515059"]Hi mlong,

    In my previous posting, that first "@" should be "[ c o d e ]" whilst the second "@" should be "[ / c o d e ]", without the spaces. I'll get the hang of this forum yet! ;-)

    Stuart
    [/quote]

    Sorry, I did not want to confuse you. I am always using the "@" for code wrappings, because it is simply faster. ;-)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.