Is it possible to use Qt.createComponent("Dialog.qml")



  • Im trying to implement a generic dialog system. Therefore I want to create different dialogs dynamically. But when I try to use

    Qt.createComponent("Dialog.qml")
    

    I get

    qml: Error creating new dialog, expected component status to be READY but it was not!
    qml: Component status is: 3
    qml: qrc:/Dialog.qml:-1 File not found
    

    And I realised that there is no Qml-File in the Qt-Install-Directory that represents a dialog. What I found was the plugin/module QtQuick/Dialogs and some DLL files. So my question is what name should I supply when using Qt.createDialog("<file_name.qml>") on native QML components like Dialog, Button or Label?


  • Moderators

    Hi @Volkeracho
    Not sure about the Dialog but for other components like Button or Label you can just add them in a separate file say for eg. MyButton.qml or MyLabel.qml and then use the URL's for these files depending upon where they are present i.e resource system or just local path.



  • Or you can just use QML Component:

    Component {
        id: component
        Dialog { }
    }
    

    Creating an instance is a matter of calling Component::createObject():

    var dialog = component.createObject(parent);


  • Thanks a lot both of you, this will do nicely!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.