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. How to use an id an of a file.qml in the main file.qml?
Forum Updated to NodeBB v4.3 + New Features

How to use an id an of a file.qml in the main file.qml?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 347 Views 2 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.
  • N Offline
    N Offline
    Ngouda
    wrote on last edited by
    #1

    Hello to all,
    In my project I have two files : file1.qml and main.qml
    In the file1.qml I defined dynamic functions to draw a curve and in the timer(with id:myTimer) I call these functions.

    Now in my main, I want to call the id of the timer (myTimer) which is in the file1.qml to be able to use it when I click on a button.
    What I don't know is how to call this id: myTimer in my main.
    I tried aliases like :
    Property alias toStop: myTimer

    But I get the error" id myTimer not find".

    sierdzioS 1 Reply Last reply
    0
    • N Ngouda

      Hello to all,
      In my project I have two files : file1.qml and main.qml
      In the file1.qml I defined dynamic functions to draw a curve and in the timer(with id:myTimer) I call these functions.

      Now in my main, I want to call the id of the timer (myTimer) which is in the file1.qml to be able to use it when I click on a button.
      What I don't know is how to call this id: myTimer in my main.
      I tried aliases like :
      Property alias toStop: myTimer

      But I get the error" id myTimer not find".

      sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      @Ngouda said in How to use an id an of a file.qml in the main file.qml?:

      Now in my main, I want to call the id of the timer (myTimer) which is in the file1.qml to be able to use it when I click on a button.
      What I don't know is how to call this id: myTimer in my main.
      I tried aliases like :
      Property alias toStop: myTimer
      But I get the error" id myTimer not find".

      You cannot access id of any external QML file. QML engine does not allow it. What you can do is create an alias property in your file1.qml and then read that in main.

      /// File1.qml (QML components HAVE TO start with upper case letter!)
      
      Item {
        property alias timer: myTimer
        /// ...
      
      /// main.qml
      File1 {
       id: myFile
      }
      
      Button {
        onClicked: myFile.timer.start()
      
      

      (Z(:^

      1 Reply Last reply
      1
      • N Offline
        N Offline
        Ngouda
        wrote on last edited by
        #3

        @sierdzio thanks you, that work well

        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