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. using QML files as items in main.qml
Qt 6.11 is out! See what's new in the release blog

using QML files as items in main.qml

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 564 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
    MaximBozek
    wrote on last edited by MaximBozek
    #1

    Hi,

    I created a qml file, for example Can.qml. Then I would call this qml file as a item in main.qml to be able to access variables created in main.qml in the Can.qml file:

    Can  {
        id: can_page
        visible: false
    }
    

    I used this in other project and that worked fine.
    Now for some reason, I get this error: qrc:/Test_Project_Display/main.qml:41:5: Can is not a type
    This is my projects structure:

    2e2d385d-d9e5-49b9-aa30-b0a911e79f69-image.png

    What could be the issue here?

    Pl45m4P 1 Reply Last reply
    0
    • M MaximBozek

      Hi,

      I created a qml file, for example Can.qml. Then I would call this qml file as a item in main.qml to be able to access variables created in main.qml in the Can.qml file:

      Can  {
          id: can_page
          visible: false
      }
      

      I used this in other project and that worked fine.
      Now for some reason, I get this error: qrc:/Test_Project_Display/main.qml:41:5: Can is not a type
      This is my projects structure:

      2e2d385d-d9e5-49b9-aa30-b0a911e79f69-image.png

      What could be the issue here?

      Pl45m4P Offline
      Pl45m4P Offline
      Pl45m4
      wrote on last edited by Pl45m4
      #2

      @MaximBozek said in using QML files as items in main.qml:

      What could be the issue here?

      Where is your "Can.qml" file now? The project's QML dir only shows the main.qml.
      If the other QML module/file (Can.qml) is not in the directory, you need to import it.

      Like (I'm not a QML expert)

      // main.qml
      import "qrc:/qml/elements"
      

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      M 1 Reply Last reply
      1
      • Pl45m4P Pl45m4

        @MaximBozek said in using QML files as items in main.qml:

        What could be the issue here?

        Where is your "Can.qml" file now? The project's QML dir only shows the main.qml.
        If the other QML module/file (Can.qml) is not in the directory, you need to import it.

        Like (I'm not a QML expert)

        // main.qml
        import "qrc:/qml/elements"
        
        M Offline
        M Offline
        MaximBozek
        wrote on last edited by
        #3

        @Pl45m4 wow, thanks this worked now. Also tried putting new .qml files in that QML directory ,and this didnt work. importing works through :0

        Pl45m4P 1 Reply Last reply
        0
        • M MaximBozek has marked this topic as solved on
        • M MaximBozek

          @Pl45m4 wow, thanks this worked now. Also tried putting new .qml files in that QML directory ,and this didnt work. importing works through :0

          Pl45m4P Offline
          Pl45m4P Offline
          Pl45m4
          wrote on last edited by
          #4

          @MaximBozek

          You can also add your main.qml to the resources.
          The QML directory with main.qml is created when starting a new QML project in QtCreator.


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          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