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 add private uri to QML Plugin
Qt 6.11 is out! See what's new in the release blog

How to add private uri to QML Plugin

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlqt quickpluginc++
2 Posts 2 Posters 1.4k 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.
  • shavS Online
    shavS Online
    shav
    wrote on last edited by
    #1

    Hi everyone!

    I have a plugin for QML on C++. In this plugin I have a few classes which I want to use as a private in QML but don't want to share it to public users. I don't know any ways to create private QML types so I decide to create a special url. For example my plugins has a uri like:

    com.company.sdk
    

    and I've use it in QML like:

    import com.company.sdk 1.0
    

    But I want to create another uri for private classes something like this:

    com.company.sdk.private

    And than use it like:

    import com.company.sdk.private 1.0
    

    I try do this:

    QString privateUri = QString("%1.private").arg(uri);
    qmlRegisterSingletonType<MySingelton>(privateUri.toStdString().c_str(), 1, 0, "MySingelton", cache_manager_singletontype_provider);
    

    But when I try to load my test application I received error:

    QQmlApplicationEngine failed to load component
    qrc:/main.qml:5 static plugin for module "com.company.sdk" with name "SDKPlugin" cannot be loaded: Cannot install singleton type 'MySingelton' into unregistered namespace 'com.company.sdk.private'
    

    What I do wrong? How I can register a new namespace for my plugin? Is this possible?

    Mac OS and iOS Developer

    1 Reply Last reply
    0
    • jpnurmiJ Offline
      jpnurmiJ Offline
      jpnurmi
      wrote on last edited by
      #2
      • workaround A: register private types in initializeEngine() instead
      • workaround B: remove the protected module identifier line from the qmldir file
      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