Can't Update MessageDialog Properties from C++: UI Does Not Change???



  • I am trying to change the title and text property of a QML MessageDialog from my C++ code. I see the properties changed in the object via the debugger, but the screen image does not change. I have spent hours trying to figure out what I am doing wrong but am still baffled as to why it is not working. Any help would be much appreciated.

    My MsgBox.qml file:

    import QtQuick 2.6
    import QtQuick.Dialogs 1.2

    Item {
    property alias title: msgbox.title
    property alias text: msgbox.text

    MessageDialog {
    	objectName: "MsgBox"
    	id: msgbox
    	title: "Title From File"
    	text: "Text from file."
    	onAccepted: {
    		console.log( "quiting application" );
    		Qt.quit()
    	}
    	Component.onCompleted: { 
    		visible = true 
    	}
    }
    

    }

    My function that updates the properties:

    ClassFoo::MsgBox()
    {
    QQuickView* v = new QQuickView( m_engine, m_rootWindow );
    v->setSource( QUrl("qrc:/MsgBox.qml") );
    v->show();

    QQuickItem* object = v->rootObject();
    object->setProperty( "title", "Title From Function" );
    object->setProperty( "text", "Text from function." );
    // or
    QQmlProperty( object, "title" ).write("Title From Function");
    QQmlProperty( object, "text" ).write("Text from function.");
    }


Log in to reply
 

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