Skip to content
  • 0 Votes
    2 Posts
    345 Views
    jeremy_kJ

    @Tom-asso said in Access read-only C++ property from QML:

    Here is my QML:

    ApplicationWindow { [...] property string testString: SharedConstants.testString Component.onCompleted: {console.log("onCompleted"); console.log("testString: ", testString)}

    But I will be adding other stuff to SharedConstants (e.g. enum) so I must actually register SharedConstants (as described here) in main.cpp:

    // Register SharedConstants so QML can access its properties qmlRegisterType<SharedConstants>("SharedConstants", 1, 0, "SharedConstants");

    Debugging shows that the designated C++ accessor function getTestString() is not invoked either.
    What am I doing wrong here?

    qmlRegisterType registers an instantiable type, but the QML code above attempts to use it as a singleton. Either instantiate an instance of the type in QML, or use one of the singleton registration methods such as QML_SINGLETON, qmlRegisterSingletonInstance, or qmlRegisterSingletonType.

  • 0 Votes
    6 Posts
    1k Views
    JonBJ

    @vicky_mac said in Memory leak in QML example project:

    Is there anyway we can prevent that?

    No, as already replied in your other thread asking exactly the same, which you have not referenced from this topic. But you can keep asking the same. Or, you can look through the source code, find the exact point of the leak you claim, and fix it.

    Apologies, that was https://forum.qt.io/topic/152049/stackview-is-cause-of-memory-leak, you do not seem to be the same author, though they look similar.

    I also notice you are using Qt 5.12. Qt Company is not going to be addressing anything in that version.

  • 0 Votes
    1 Posts
    494 Views
    No one has replied