2013-10-23 44 views
0

我讓一個程序工作不同的qml文件,首先顯示一個獲取idClient的屏幕,點擊一個按鈕並發表一個帖子(它工作正常),其次,新屏幕獲取idVent,點擊一個按鈕,發表一篇文章(這也是作品),最後第三個屏幕顯示大量數據。我的問題是偶爾可能會在post方法中得到一個錯誤,並且我會顯示一條錯誤消息(這會消失與按鈕),並且我給出如何將參數字符串說出錯(如何顯示字符串不是問題,問題是如何通過字符串)。管理多個qml文件

我將有一個加載程序元素,並且如果我不包含錯誤管理,則工作正常。 而我不希望qml中的C++對象(例如我的類Httppost)。 我QML代碼是這樣的:

Loader { 
    id: pageLoader // ID needed for so we can later delete the item 
    source: "AnimationSplash.qml" 
    focus: true 
    property bool valid: item !== null 
    anchors.horizontalCenter: parent.horizontalCenter 
    objectName: "switchPages" 
} 

Timer { 
    id: firstPhaseTimer 
    interval: 750 
    running: true 
    repeat: false 

    onTriggered:{ 
     pageLoader.item.opacity=0; 
     pageLoader.source="SearchRecipient.qml" 
    } 
} 

Connections{ 
    target:pageLoader.item 
    ignoreUnknownSignals: true 
    onPostIdClient: { 
     postClient(pageLoader.typeId, pageLoader.textIdClient) 
    } 
    onPostIdVent: { 
     postVent(pageLoader.textIdVent) 
     pageLoader.source="MainView.qml" 
    } 
} 

postIdClient和postIDVent從加載文件的信號,但任何人有一個suggerence如何變化ErrorScreen,如果我的管理錯誤的是C++。

我的C++構造函數代碼(是我加載main.qml文件)是這樣的:

QObject *mainObject; 
    QQuickView view; 

    view.setSource(QUrl::fromLocalFile("./ui/main.qml")); 
    view.setResizeMode(QQuickView::SizeRootObjectToView); 
    view.show(); 


    mainObject=view.rootObject(); 

    QObject *switcher=mainObject->findChild<QObject*>(""); 
    if(mainObject) 
    { 
    QObject::connect(mainObject, SIGNAL(postClient(QString,QString)), this, SLOT(postingClientData(QString,QString)),Qt::UniqueConnection); 
    QObject::connect(mainObject, SIGNAL(postVent(QString)), this, SLOT(postIdVent(QString)),Qt::UniqueConnection); 
    } 

最後,如何讀取和設置的MainView的性質,如果我沒有從孩子的QObject訪問QQuickView(我用這個clang加載main.qml)

+0

感謝您對標題的更正 – APRocha

回答

0

我得到了parcial答案,我用一個變量屬性來保持頁面的控制,並在main.qml中聲明新的信號,這個信號是在加載項的信號被執行,並且在C++中當錯誤被註冊時,我in​​voque qml函數,並且給出字符串錯誤的參數。但我沒有采取和管理我的mainView.qml(顯示所有數據時的屏幕)的形式,如果我加載加載程序組件,實際上我加載如何在main.qml中的組件,我顯示代碼。

Rectangle{ 
    width: 535 
    height: 700 
    color: "#939393" 
    id: main 

    signal changePage()//string page, variant data, int state) 

    property alias pageLoaded: pageLoader.item 
    signal postClient(string typeId,string textIdClient) 
    signal postVent(string textIdVent) 

    property int page 
    property string messageError: "" 

    onChangePage:{ 
     mainViewofProgram.opacity=1 
    } 


    Loader { 
    id: pageLoader // ID needed for so we can later delete the item 
    source: "AnimationSplash.qml" 
    focus: true 
    property bool valid: item !== null 
    anchors.horizontalCenter: parent.horizontalCenter 
    objectName: "switchPages" 
    } 

    Timer { 
    id: firstPhaseTimer 
    interval: 750 
    running: true 
    repeat: false 

    onTriggered:{ 
     pageLoader.item.opacity=0; 
     pageLoader.source="SearchRecipient.qml" 
     } 
    } 


    MainView{ 
     id:mainViewofProgram 
     opacity: 0 
     width: parent.width 
     height: parent.height 
     objectName: "facturador" 
    } 


    Connections{ 
    target:pageLoader.item 

    ignoreUnknownSignals: true 

    onPostIdClient: { 
     postClient(typeId, textId) 
     console.log(typeId,textId) 

     if(messageError=="") 
     {pageLoader.source = "SearchVent.qml"} 

     else 
     {pageLoader.source = "ErrorServer.qml" 
      page=1} 
     } 

    onPostIdVent: { 
     postVent(textIdVent) 

     if(messageError=="") 
      { 
      pageLoader.source="" 
      pageLoader.opacity=0 
      changePage() 
      } 
     else 
     {pageLoader.source = "ErrorServer.qml" 
      page=2} 
     } 


    onReturnPreviusPage: 
     { 
     if(page==2) 
      pageLoader.source="SearchVent.qml" 
     if(page==1) 
      pageLoader.source="SearchRecipient.qml" 
     } 

    } 
    }