I have the following qml file:
import QtQuick 2.2
import QtQuick.Dialogs 1.2
FileDialog
{
property string myTitle: "Select file to open"
property string myfilter: "All files (*)"
id: fileDialog
objectName: "fileDialogObj"
title: myTitle
folder: shortcuts.home
sidebarVisible : true
nameFilters: [ myfilter ]
onAccepted:
{
close()
}
onRejected:
{
close()
}
Component.onCompleted: visible = true
}
I want to set the title
property from the C++ code. I have code that looks like:
QQmlEngine engine;
QQmlComponent component( &engine );
component.loadUrl( QUrl( QStringLiteral( "qrc:/qml/my_file_dialog.qml" ) ) );
QObject* object = component.create();
object->setProperty( "myTitle", "Open file!" );
The title has the initial value (Select file to open
) of the property myTitle
and never changes to Open file!
What am I doing wrong?
UPDATE I've also tried to update the title directly from C++ code.
Considering I have the dialog object, I update the tile like this:
QQmlProperty::write( dialog, "title", "testing title" );
And also like this:
dialog->setProperty( "title", "testing title" );
The property title of the file dialog is not set.
As @Tarod mentioned in his answer, it seems to be a bug.
Or am I missing something?