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. Create linked qml module

Create linked qml module

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 83 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.
  • A Offline
    A Offline
    Andrew Strokov
    wrote 6 days ago last edited by Andrew Strokov 5 Dec 2025, 09:15
    #1

    I create qml module DataModel

        qt_add_library(DataModel SHARED)
        qt_add_qml_module(DataModel
        URI DataModel
        VERSION 1.0
        PLUGIN_TARGET DataModel
        TYPEINFO plugins.qmltypes
        SOURCES data_model.h data_model.cpp)
    

    DataModel class is QML_SINGLETON
    Can i create a module like this?
    In qt guide https://doc.qt.io/qt-6/qtqml-writing-a-module.html
    they recommends create qt_add_library with STATIC flag

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SuhasKrishanamurthy
      wrote 6 days ago last edited by
      #2

      Yes, you can create a QML module like this using qt_add_library(DataModel SHARED) — it is valid and supported by Qt, especially when your module is meant to be used as a shared QML plugin across multiple applications.

      The Qt guide recommends using STATIC for modules that are internal to a specific application because:

      Static libraries avoid deployment issues with plugins (like qmldir, plugin paths, etc.).

      They simplify application packaging since everything is built into the app binary.

      However, in your case:

      You're defining a QML_SINGLETON, which is typically registered via a plugin.

      You're using PLUGIN_TARGET, which indicates you're building a QML plugin.

      Shared builds make sense when the module is intended to be reused and dynamically loaded by the QML engine.

      A 1 Reply Last reply 6 days ago
      1
      • S SuhasKrishanamurthy
        6 days ago

        Yes, you can create a QML module like this using qt_add_library(DataModel SHARED) — it is valid and supported by Qt, especially when your module is meant to be used as a shared QML plugin across multiple applications.

        The Qt guide recommends using STATIC for modules that are internal to a specific application because:

        Static libraries avoid deployment issues with plugins (like qmldir, plugin paths, etc.).

        They simplify application packaging since everything is built into the app binary.

        However, in your case:

        You're defining a QML_SINGLETON, which is typically registered via a plugin.

        You're using PLUGIN_TARGET, which indicates you're building a QML plugin.

        Shared builds make sense when the module is intended to be reused and dynamically loaded by the QML engine.

        A Offline
        A Offline
        Andrew Strokov
        wrote 6 days ago last edited by
        #3

        @SuhasKrishanamurthy Thank you! By the way, using qt_add_qml_module together with qt_add_library or qt_add_executable means embedding the qml module?
        and if you use qt_add_qml_module separately, will a plugin be created?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SuhasKrishanamurthy
          wrote 6 days ago last edited by
          #4

          Yes — if you combine qt_add_qml_module() with a STATIC library or an executable target without a PLUGIN_TARGET, the QML types get embedded in the binary. No plugin is generated.

          And if you define qt_add_qml_module() with a PLUGIN_TARGET, and the library is built as SHARED, Qt will generate a plugin that the QML engine can dynamically load.

          A 1 Reply Last reply 6 days ago
          0
          • S SuhasKrishanamurthy
            6 days ago

            Yes — if you combine qt_add_qml_module() with a STATIC library or an executable target without a PLUGIN_TARGET, the QML types get embedded in the binary. No plugin is generated.

            And if you define qt_add_qml_module() with a PLUGIN_TARGET, and the library is built as SHARED, Qt will generate a plugin that the QML engine can dynamically load.

            A Offline
            A Offline
            Andrew Strokov
            wrote 6 days ago last edited by
            #5

            @SuhasKrishanamurthy Thanks! :)

            1 Reply Last reply
            0
            • A Andrew Strokov has marked this topic as solved 5 days ago

            1/5

            12 May 2025, 09:08

            • Login

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