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. "Loader" functionality inside a Singleton QtObject
Forum Updated to NodeBB v4.3 + New Features

"Loader" functionality inside a Singleton QtObject

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 501 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.
  • vikramgV Offline
    vikramgV Offline
    vikramg
    wrote on last edited by vikramg
    #1

    I am specifying (and accessing) app settings from a singleton QtObject defined in a Config.qml file. This is working just fine (more details here). But now I would like to have multiple config files corresponding to various products (e.g. ConfigProd1.qml, ConfigProd2.qml etc). In building the app for a different product, I would like to be able to just source a new ConfigProd.qml inside the Config.qml, so that the rest of the code can just refer to Config.qml without caring about what product it was configured for.

    I first thought perhaps I might use a Loader in the QtObject in Config.qml:

    import QtQuick 2.0
    pragma Singleton
    
    QtObject {
    
        objectName: "Config"
    
        Loader {
            source: "ConfigProd1.qml"
        }
      
    }
    

    where ConfigProd1.qml has

    import QtQuick 2.0
    
    QtObject {
    
        objectName: "ConfigProd1"
    
        readonly property int width: 37
        readonly property int height: 43
    }
    

    but that didn't work. Presumably Loaders work only with visual items? My second thought was that it might be accomplished via a directory-listing qmldir file with the line

    Config ConfigProd1.qml
    

    but that doesn't work either, I think because I have to register the type explicitly as

    qmlRegisterSingletonType(QUrl(QStringLiteral("qrc:/AppConfig/Config.qml")), "com.test.Config", 1, 0, "Config");
    

    Is there any way to accomplish what I want?

    1 Reply Last reply
    0
    • vikramgV Offline
      vikramgV Offline
      vikramg
      wrote on last edited by
      #2

      For now, I have worked around this by symlinking the product config files to Config.qml thus:

      $ ln -sf ConfigProd1.qml Config.qml
      

      Qt Creator doesn't seem to have any problems with symlinked files, and VCSs (Mercurial in my case) seem to support them fine as well.

      Would still be nice to get an idiomatic QML technique to do this if there is one, but this works for now.

      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