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. Accessing QML objects from .rcc files from Loader objects

Accessing QML objects from .rcc files from Loader objects

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 772 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.
  • S Offline
    S Offline
    salarelv
    wrote on last edited by
    #1

    Hi,

    I am building a modular app that can use modules for example a Clock and I would like to distribute these modules as .rcc files.
    Everything is fine when I display the Clock in regular QML files but if I load a file with Loader it doesn't recognize the Clock object.
    In my main.cpp

        QResource::registerResource("./modules/clock.rcc");
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    

    In my main.qml

    import QtQuick 2.9
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.2
    
    ApplicationWindow {
        id: window
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        Row {
            Clock {
                //This Clock works
            }
    
            Loader {
               id: myLoader
               source: "./layout/test.qml"
            }
        }
    }
    

    In ./layout/test.qml

    import QtQuick 2.0
    
    Item {
        Clock {
           // does not work
        }
    }
    
    

    It throws the following error: Clock is not a type

    Does somebody have a good idea how can use the Clock module from the loaded QML file?

    S 1 Reply Last reply
    0
    • S salarelv

      Hi,

      I am building a modular app that can use modules for example a Clock and I would like to distribute these modules as .rcc files.
      Everything is fine when I display the Clock in regular QML files but if I load a file with Loader it doesn't recognize the Clock object.
      In my main.cpp

          QResource::registerResource("./modules/clock.rcc");
          engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
      

      In my main.qml

      import QtQuick 2.9
      import QtQuick.Window 2.2
      import QtQuick.Controls 2.2
      
      ApplicationWindow {
          id: window
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Row {
              Clock {
                  //This Clock works
              }
      
              Loader {
                 id: myLoader
                 source: "./layout/test.qml"
              }
          }
      }
      

      In ./layout/test.qml

      import QtQuick 2.0
      
      Item {
          Clock {
             // does not work
          }
      }
      
      

      It throws the following error: Clock is not a type

      Does somebody have a good idea how can use the Clock module from the loaded QML file?

      S Offline
      S Offline
      salarelv
      wrote on last edited by
      #2

      Answering my own question again.

      import "../" in the test.qml helped.

      PS! Thanks to DanChapman

      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