2017-05-05 19 views
1

からタイトルを設定します。QMLのFileDialogは、私は、次のQMLファイルを持っている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!"); 

タイトルは財産myTitleの初期値(Select file to open)が、決して私が間違って何をやっているOpen file!

に変更します。私は次のようなコードがありますか?

UPDATE また、C++コードから直接タイトルを更新しようとしました。

私は、ダイアログオブジェクトを持って考えると、私はこのようなタイルを更新します。このような

QQmlProperty::write(dialog, "title", "testing title"); 

もが:

dialog->setProperty("title", "testing title"); 

ファイルダイアログのプロパティのタイトルが設定されていません。

@Tarodが彼の答えで言いましたように、バグのようです。

何か不足していますか?我々はまた、あなたが他のプロパティが正しく更新されてチェックすることができ

title = myTitle

の代わりに

title = "xxx"

を設定した場合、次のコードが動作するため

答えて

0

それは、バグが考えられます。私。 sidebarVisible

main.cppに

#include <QGuiApplication> 
#include <QQmlApplicationEngine> 
#include <QQmlComponent> 
#include <QQmlProperty> 
#include <QDebug>  

int main(int argc, char *argv[]) 
{ 
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); 
    QGuiApplication app(argc, argv); 

    QQmlEngine engine; 
    QQmlComponent component(&engine, QUrl(QLatin1String("qrc:/main.qml"))); 
    QObject *object = component.create(); 

    QObject *fileDialog = object->findChild<QObject*>("fileDialogObj"); 

    if (fileDialog) 
    { 
     fileDialog->setProperty("myTitle", "new title"); 
     fileDialog->setProperty("sidebarVisible", true); 
     qDebug() << "Property value:" << QQmlProperty::read(fileDialog, "myTitle").toString(); 
    } else 
    { 
     qDebug() << "not here"; 
    } 

    return app.exec(); 
} 

main.qml

import QtQuick 2.7 
import QtQuick.Controls 2.0 
import QtQml 2.2 
import QtQuick.Dialogs 1.2 

Item { 
    FileDialog 
    { 
     property string myTitle: fileDialog.title 
     property string myfilter: "All files (*)" 

     id: fileDialog 
     objectName: "fileDialogObj" 
     title: "Select file to open" 
     folder: shortcuts.home 
     sidebarVisible : true 
     nameFilters: [ myfilter ] 

     onAccepted: 
     { 
      close() 
     } 
     onRejected: 
     { 
      close() 
     } 
     Component.onCompleted: 
     { 
      visible = true 
     } 
     onMyTitleChanged: 
     { 
      console.log("The next title will be: " + myTitle) 
      title = myTitle 
     } 
    } 
} 
+0

他のフィードバックが与えられていない場合、私は、これはバグであれば明確にするためにしばらく待ってます私はあなたの答えを受け入れます:それはバグです。 – mtb

関連する問題