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. Can't Update MessageDialog Properties from C++: UI Does Not Change???
Qt 6.11 is out! See what's new in the release blog

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

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 406 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.
  • E Offline
    E Offline
    Ed Buchwalter
    wrote on last edited by
    #1

    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.");
    }

    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