Unsolved 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.2Item {
property alias title: msgbox.title
property alias text: msgbox.textMessageDialog { 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.");
}