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. Using a singleton without importing it?

Using a singleton without importing it?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 2 Posters 1.1k 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.
  • N Offline
    N Offline
    nbigaouette
    wrote on last edited by
    #1

    Hi all,

    I want to create a QML singleton with some properties in it (for example some colors to reuse). I'd like that singleton to be usable both when launching my QML application with qmlscene and from C++ (through a QApplication and QQmlApplicationEngine).

    The only way I've found was to create a qmldir beside my Main.qml and MySingleton.qml with singleton MySingleton 0.1 MySingleton.qml in it and importing it using import "." in Main.qml.

    Is there a way to prevent having to import "." wherever I want to use my singleton? I find that import statement confusing as it's not explicit that I'm importing the current directory to get access to the singleton.

    Normally, I can create a component, say MyComponent and save it to MyComponent.qml. I can then automatically use this component in other qml files through its filename (without extension). Why can't I do this with the singleton?

    Thanks!

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xargs1
      wrote on last edited by
      #2

      I believe the import "." requirement is a bug that's in the bug database.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nbigaouette
        wrote on last edited by
        #3

        Just for completeness, the bug is this one: https://bugreports.qt.io/browse/QTBUG-34418

        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