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. When to register c++ singleton types in QML module plugins?

When to register c++ singleton types in QML module plugins?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
qmlmodulepluginsingletonc++
1 Posts 1 Posters 523 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.
  • K Offline
    K Offline
    Knutid
    wrote on last edited by
    #1

    Hello.

    I have a qml plugin created with CMake/qt_add_qml_module() that contains some C++ QML singletons. I can see the generated x_qmltyperegistrations.cpp file contains normal type registrations for these singletons as well. The module also contains some other non-singleton C++ types which are also registered in that generated cpp file.

    These singletons need a call to qmlRegisterSingletonType<>() in order to register their creation functions, but I'm having some issues determining when or where these calls should be made.

    If I add them before engine creation, I get some errors on Android builds saying that the module cannot be loaded because the namespace already contains types. Strangely I don't get these errors on the Linux desktop.

    I tried to create my own plugin sources and use initializeEngine() to add these functions, but at that point the module has been locked and new types cannot be added.

    Any suggestions for how to solve this?
    Currently I'm using a hackish solution where I mark the generated x_qmltyperegistrations.cpp file as a HEADER_ONLY and create my own where I include this cpp file and do some preprocessor magic to inject my qmlRegisterSingletonType<>() calls when the types are registered, but this is not pretty.

    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