Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

How to reload QML file with ApplicationWindow object?

$
0
0
Hi guys, I develop application with QML Desktop Component and can’t understand how to refresh main window from QML or C++ code. I created a class which created a main window by code bool QtQuick2ApplicationViewer::showQmlFile(QString file) {     m_qmlFile = file;     m_mainComponent->loadUrl(QUrl(m_qmlFile));     if(!m_mainComponent->isReady())     {         qWarning("%s", qPrintable(m_mainComponent->errorString()));         return false;     }     QObject *topLevel = m_mainComponent->create();     m_mainWindow = qobject_cast<QQuickWindow *>(topLevel);     if(!m_mainWindow)     {         qWarning("Error: Your root item has to be a Window.");         return false;     }       QObject* obj = m_mainWindow->findChild<QObject*>("logManager");     connect(obj, SIGNAL(reload(QString)), SLOT(reload(QString)));       m_mainWindow->showMaximized();       return true; } I want choosing file from menu and the refresh QML elements. If I understand correctly I must reload QML file, but I don’t know how I can do it? Maybe exist some way how to reload QML elements from QML? import QtQuick 2.0 import com.shav.mdl 1.0  //My custom plugin for QML 2.0 import QtDesktop 1.0 import Qt.labs.folderlistmodel 1.0   ApplicationWindow {     id: mainWindow     width: 1024  height: 768     title: "Mobile Debug Log Viewer"       property alias manager: logManager       About {         id: aboutWindow         title: "About"     }       Preferences {         id: preferencesWindow         title: "Settings"     }       Simulator {         id: iphoneWindow         title: "iPhone 4S"     }       MdlManager {  //Create a object from plugin which must work with file.         id: logManager           signal reload(string logFile);           objectName: "logManager"         onMdlLogParserDidFinished: {             console.debug("File '"+parser.logFilePath+"' was parsed");             //Must reload interface components for setting a new data from file.         }     }       FileDialog {         id: openMdlFile         title: "Open Log file"         nameFilters: ["*.mdl"]         selectMultiple: false         onAccepted: {             logManager.reload(filePath);         }     }       menuBar: MenuBar {         Menu {             text: "File"               MenuItem {                 text: "Open Log..."                 shortcut: "Ctrl+O"                 onTriggered: {                     openMdlFile.open();                 }             }         }         Menu {             text: "Simulators"               Menu {                 text: "iPhone"                   MenuItem {                     text: "iPhone 4S"                       onTriggered: {                         iphoneWindow.showNormal();                     }                 }             }   /*            Menu {                 text: "iPad"                 enabled: false                 visible: false             }*/               Separator { }               MenuItem {                 text: "Enabled Brodcast Images"                 checkable: true                   onCheckedChanged: {                     if(checked)                     {                         //Enabled                     }                     else                     {                         //Disabled                     }                 }             }         }         Menu {             text: "Preferences"               MenuItem {                 text: "Settings"                 onTriggered: {                     preferencesWindow.showNormal();                 }             }         }         Menu {             text: "Help"               MenuItem {                 text: "About..."                 onTriggered: {                     aboutWindow.showNormal();                 }             }         }     }       ServerInformation {         id: serverList         anchors {verticalCenter: parent.verticalCenter}         width: 400         height: parent.height - 100         x: -(serverList.width - 40)         opacity: 0.0         bookmarkImage: "images/art-add-bookmark.png"           NumberAnimation {             id: serverListShow             running: false             target: serverList             property: "opacity"             duration: 1000             easing.type: Easing.InOutBack             to: 1.0         }     }       Rectangle {         anchors {top: mainWindow.bottom}         color: "transparent"         clip: true         width: parent.width         height: parent.height           LeftSideBar {   //This must be reloaded             id: leftBar             color: "black"             width: 400             height: parent.height             x: -leftBar.width               NumberAnimation {                 running: true                 target: leftBar                 property: "x"                 duration: 700                 easing.type: Easing.InOutBack                 to: 0             }          }           ContentView { //This must be reloaded    id:contentView             width: parent.width - 400             height: parent.height             x: leftBar.width             y: -parent.width             color: "transparent"               NumberAnimation {                 running: true                 target: contentView                 property: "y"                 duration: 1000                 easing.type: Easing.InOutBack                 to: 0                 onRunningChanged: {                     serverListShow.start();                 }             }         }     } } If somebody know how I can reload elements from QML/C++, please help me. Thanks!

Viewing all articles
Browse latest Browse all 4972

Trending Articles