Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Newbie error
QtWS25 Last Chance

Newbie error

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 848 Views
  • 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.
  • D Offline
    D Offline
    djm2
    wrote on 28 Nov 2013, 10:44 last edited by
    #1

    Hi there

    I am brand new to QT creator and I am having a problem I was hoping that someone could help with. I have a project with a few screens - .qml file for each of the screens. I have a button on one screen and when the user presses the button I want to navigate/load another screen.

    I have the following code -

    @ ImageButton {
    id: image_button1
    x: 70
    y: 214
    width: 132
    height: 80
    text: "OUTPUTS"
    font.bold: false
    font.family: "Arial"
    imageUp: "images/internal_button_up.bmp"
    font.pixelSize: 18
    textColor: "#000000"
    imageDown: "images/internal_button_dn.bmp"
    onButtonClick: root.message("../src/mainmenu.qml");
    }@

    The line - onButtonClick: root.message("../src/mainmenu.qml should take the user to another screen when the button is pressed. However when I run the code I get the following error - "ReferenceError: Can't find variable: root". The file mainmenu.qml is held in the project folder of the same project as the file that contains the above code.

    David

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 28 Nov 2013, 11:21 last edited by
      #2

      IDs are not accessible from other QML files. If your "root" is defined in mainmenu.qml, then it is not visible in any other QML file.

      (Z(:^

      1 Reply Last reply
      0
      • D Offline
        D Offline
        djm2
        wrote on 28 Nov 2013, 11:23 last edited by
        #3

        Can you suggest a way to switch between the files? ie click on say an exit button and have it take you back to a main menu?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 28 Nov 2013, 11:27 last edited by
          #4

          Use a Loader in MainMenu, and communicate using signals and slots mechanism. This is probably too involved for a newbie.

          Another option is the solution found in Qt Examples and other demos: store all pages in a single QML file, and switch between them using States and Transitions.

          All this is in the documentation, just give it a search :)

          (Z(:^

          1 Reply Last reply
          0

          2/4

          28 Nov 2013, 11:21

          • Login

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