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. Static Library & use QML_ELEMENT to Expose the classes
Forum Updated to NodeBB v4.3 + New Features

Static Library & use QML_ELEMENT to Expose the classes

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 1 Posters 364 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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Qt Champions 2022
    wrote on last edited by
    #1

    Hi All

    Qn - How to use the QObject classes bundled inside the static library using QML_ELEMENT.

    Details of my issue -

    1. Linux Platform. Qt 6.x
    2. Built static library. It contains the follwing.
      a. CarInfo - Uses QML_ELEMENT (no qmlregistertype)
      b. TyreInfo - Uses QML_ELEMENT (no qmlregistertype)
      c. MyStar.qrc - This contains the qml file(MyStyles.qml)

    When I build the static library it generates the cpp file with following entry
    Q_QMLTYPE_EXPORT void qml_register_types_CarInfo()
    {
    qmlRegisterTypesAndRevisions<CarInfo>("CarInfo", 1);
    qmlRegisterTypesAndRevisions<TyreInfo>("CarInfo", 1);
    qmlRegisterModule("CarInfo", 1, 0);
    }

    I'm linking the static library with my applicaiton. In order to use the classes present in static library, method qml_register_types_CarInfo() should be explicitly called.

    Is there anyother way to call the above method or something else ?

    Since method should be explicitly called, I need to modify the signature to
    extern "C" void qml_register_types_CarInfo(){}

    Is there any best practice when I bundle the classes in static library with QML_ELEMENT ?

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

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      Some additional inputs.

      On windows with MingW compiler it behaves differently.

      1. On Windows extern "C" key is not required.
      2. I need to load the library explicitly using QLibrary both on Linux & Windows.
      3. Once I do an import in qml, qml_register_types_CarInfo(){} is called on by qmlengine.

      Only extern "C" is required in Linux.

      Is this a bug ? Anyone noticed this issue ?

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

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        Further investigation on this.
        Some how we need to load the staticlibrary.

        1. On Linux 6.4.3 Q_INIT_RESOURCE(MyLib). This automatically loaded the libary & called qml_register type.
        2. Windows 6.61 - Q_INIT_RESOURCE(MyLib) - This gave me linker error saying that qInitResource_MyLib() is not defined.
          I just created the object from C++ class present in the library. It worked.
        3. We don't have to modify with extern "C". Not required.

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

        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