次のqmlファイルがあります:
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
}
title
C++ コードからプロパティを設定したい。次のようなコードがあります。
QQmlEngine engine;
QQmlComponent component( &engine );
component.loadUrl( QUrl( QStringLiteral( "qrc:/qml/my_file_dialog.qml" ) ) );
QObject* object = component.create();
object->setProperty( "myTitle", "Open file!" );
タイトルはSelect file to open
プロパティの初期値 ( ) を持ち、myTitle
変更されることはありません。Open file!
私は何を間違っていますか?
UPDATE また、タイトルを C++ コードから直接更新しようとしました。
ダイアログ オブジェクトがあることを考慮して、次のようにタイルを更新します。
QQmlProperty::write( dialog, "title", "testing title" );
また、次のようにします。
dialog->setProperty( "title", "testing title" );
ファイル ダイアログのプロパティ タイトルが設定されていません。
@Tarodが彼の回答で述べたように、それはバグのようです。
または、何か不足していますか?