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. Importing components from a plugin
QtWS25 Last Chance

Importing components from a plugin

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlimportplugin
3 Posts 2 Posters 773 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.
  • P Offline
    P Offline
    plaristote
    wrote on 21 Oct 2022, 02:18 last edited by plaristote
    #1

    Hi !
    I made my own plugin using Creating C++ Plugins for QML, and I've been trying to import components in Qt applications using import "qrc:/com/planed/components" or import com.planed.components 1.0, which have led to unsatisfying results:

    Importing a directory

    Using qrc:/com/planed/components is probably not the proper way to go, and it results in the following error:

    Module namespace 'com.planed.components' does not match import URI ':.com.planed.components'
    

    Still, I've been able to import components from sub-folders such as qrc:/com/planed/components/qml, so it is the most functional solution I've had so far...

    Importing a module

    Using import com.planed.components 1.0 only imports the C++ components registered in the plugin's registerTypes method. The QML components are nowhere to be found, despite the fact that they appear in the qmldir file located at qrc:/com/planed/components/qmldir:

    module com.planed.components
    linktarget Planedplugin
    optional plugin Planedplugin
    classname com_planed_componentsPlugin
    typeinfo Planed.qmltypes
    prefer :/com/planed/components/
    View 1.0 View.qml
    Window 1.0 Window.qml
    Application 1.0 Application.qml
    ...
    

    I would expect this to work:

    import QtQuick 2.15
    import com.planed.components 1.0 as Planed
    
    Planed.Window {
      title: "Main window"
    }
    

    but while it doesn't complain about com.planed.components not existing, it does claim that Planed.Window is "not a type".

    So, how did I end up with an empty module anyway ? How come the components declared in the qmldir file, which are indeed included in the Resource File System at the expected location, are not included with the module ?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 21 Oct 2022, 11:31 last edited by
      #2

      I feel you are missing engine.addImportPath("qrc:/") in main.cpp. Can you check this ?

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      3
      • P Offline
        P Offline
        plaristote
        wrote on 21 Oct 2022, 12:54 last edited by
        #3

        Aaand your feeling was spot on ! That was indeed the issue !
        Thank you very much !

        1 Reply Last reply
        0

        3/3

        21 Oct 2022, 12:54

        • Login

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