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. How to use singleton in another singleton

How to use singleton in another singleton

Scheduled Pinned Locked Moved QML and Qt Quick
1 Posts 1 Posters 786 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
    nekobako
    wrote on last edited by
    #1

    Hello,

    I'm using Qt 5.3.2 and I tried to use singleton object in another singleton object in the same directory.
    But the program exited with code -1.

    It is a situation such as the following. (this is just an example)

    Directory structure
    @root [directory]
    |-Test.qml (Window)
    |-singletons [directory]
    |-qmldir
    |-Colors.qml (Singleton)
    |-Red.qml (Singleton)
    |-Green.qml (Singleton)@


    qmldir
    @singleton Colors Colors.qml
    singleton Red Red.qml
    singleton Green Green.qml@


    Colors.qml
    @pragma Singleton
    import QtQuick 2.0

    QtObject {
    readonly property color colorR: "#FF0000"
    readonly property color colorG: "#00FF00"
    readonly property color colorB: "#0000FF"
    }@


    Red.qml
    @pragma Singleton
    import QtQuick 2.0
    import '.'

    QtObject {
    readonly property color color1: Colors.colorR
    }@


    Green.qml
    @pragma Singleton
    import QtQuick 2.0
    import '.'

    QtObject {
    readonly property color color1: Colors.colorG
    }@


    Test.qml:
    @import QtQuick 2.3
    import QtQuick.Controls 1.2
    import 'singletons'

    ApplicationWindow {
    width: 640
    height: 480

    Rectangle {
        anchors.centerIn: parent
        width: 100
        height: 100
        color: Red.color1
    }
    

    }
    @


    Red.qml and Green.qml are using Colors.qml by importing '.'.
    I think this part is something wrong.

    The program works fine if I remove
    @import '.'@

    from Green.qml.
    But I will not be able to use Green.color1 in Test.qml.

    Please can anyone help me with this issue?

    Thanks.

    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