Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Syntax error in "Creating a Qt Quick Application" example
Qt 6.12 LTS is out! See what's new in the release blog

Syntax error in "Creating a Qt Quick Application" example

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 8.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.
  • M Offline
    M Offline
    mlong
    wrote on last edited by
    #3

    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!

    Software Engineer
    My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #4

      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

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koahnig
        wrote on last edited by
        #5

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

        Vote the answer(s) that helped you to solve your issue(s)

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #6

          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.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mlong
            wrote on last edited by
            #7

            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.

            Software Engineer
            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #8

              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

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #9

                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

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mlong
                  wrote on last edited by
                  #10

                  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();
                  }
                  @

                  Software Engineer
                  My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #11

                    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

                    1 Reply Last reply
                    0
                    • K Offline
                      K Offline
                      koahnig
                      wrote on last edited by
                      #12

                      [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. ;-)

                      Vote the answer(s) that helped you to solve your issue(s)

                      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
                      • Unsolved