0
votes

I make a program work different qml files, first show a screen for get idClient, click a button and make a post (it's works fine), second, the new screen get idVent, click a button and make a post(this works too), and finally a third screen show a lot of data. My problem is occasionally may be get a error in post method, and I will show a message of error(this disappears with button) and I give how argument the string saying error(how show the string not is problem, the problem is how pass the string).

I will have a loader element, and works fine if i don't include the error management. And i don't want instance in qml the C++ object (for example my class of Httppost). My qml Code is this:

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 and postIDVent are signals from load files, but anyone have a suggerence how change ErrorScreen, if my manage of error is in C++.

My C++ constructor code (is where I load a main.qml file) is this:

  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); 
  }  

Finally, how read and set properties of MainView, if i don't have access from child QObject of QQuickView (i use this clase for load main.qml)

1
thanks for correction in the title - APRocha

1 Answers

0
votes

i' get the parcial answer, i use a variable property for keep a control of pages, and declare new signals in the main.qml, this signals are sent when the signals of items loaded are executed, and in C++ when error is registered, i invoque qml function, and give the string error how argument. But i don't have form of take and manage my mainView.qml (screen when all data are showed) if i load with loader component, actually i load how a component in main.qml, i show a code.

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"
       }

    }
  }