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. QML singleton in CMake (Qt 6.2)
Forum Updated to NodeBB v4.3 + New Features

QML singleton in CMake (Qt 6.2)

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 611 Views 1 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.
  • P Offline
    P Offline
    paulmasri
    wrote on last edited by
    #1

    In the documentation for Qt 6.2+, it gives an example of how to create a singleton: https://doc.qt.io/qt-6/qt-target-qml-sources.html

    The CMake code:

    set_source_files_properties(FunnySingleton.qml PROPERTIES
        QT_QML_SINGLETON_TYPE TRUE
    )
    

    results in qmldir:

    singleton FunnySingleton 2.0 FunnySingleton.qml
    

    How could I get it to put the following in qmldir instead:

    singleton FS 2.0 FunnySingleton.qml
    

    i.e. how do I rename it so that I can reference its properties elsewhere in QML as FS.xxx instead of FunnySingleton.xxx?

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      @paulmasri said in QML singleton in CMake (Qt 6.2):

      i.e. how do I rename it so that I can reference its properties elsewhere in QML as FS.xxx instead of FunnySingleton.xxx?

      https://doc.qt.io/qt-6/qt-target-qml-sources.html says:

      the name of the type itself can also be overridden using the QT_QML_SOURCE_TYPENAME property.

      so writing should achieve what you want:

      set_source_files_properties(FunnySingleton.qml PROPERTIES
          QT_QML_SOURCE_TYPENAME FS
          QT_QML_SINGLETON_TYPE TRUE
      )
      
      1 Reply Last reply
      1
      • P Offline
        P Offline
        paulmasri
        wrote on last edited by
        #3

        @GrecKo said in QML singleton in CMake (Qt 6.2):

        QT_QML_SOURCE_TYPENAME

        Thanks. I really should learn to read. It was in the same paragraph as QT_QML_SINGLETON_TYPE. 🤦

        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