1
我有以下QML文件:QML的FileDialog設置標題從C++代碼
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
}
我想設置從C++代碼的title
財產。我有一些代碼看起來像:
QQmlEngine engine;
QQmlComponent component(&engine);
component.loadUrl(QUrl(QStringLiteral("qrc:/qml/my_file_dialog.qml")));
QObject* object = component.create();
object->setProperty("myTitle", "Open file!");
標題具有財產myTitle
的初始值(Select file to open
)並不會改變對Open file!
我在做什麼錯?
UPDATE 我也試着直接從C++代碼更新標題。
考慮到我有對話框對象,我更新了瓷磚這樣的:
QQmlProperty::write(dialog, "title", "testing title");
而且也是這樣:
dialog->setProperty("title", "testing title");
文件對話框的產權未設置。
正如@Tarod在他的回答中提到的,這似乎是一個錯誤。
或者我錯過了什麼?
我會等待一段時間才能弄清楚,如果這是一個錯誤,然後,如果沒有其他信息將反饋給,我會接受你的回答:這是一個錯誤。 – mtb