How to “pull” data from c++ to qml?What are the differences between a pointer variable and a reference variable in C++?How do I iterate over the words of a string?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListWhat is the effect of extern “C” in C++?What is the “-->” operator in C++?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why is reading lines from stdin much slower in C++ than Python?How to pass data from QML to C++ as a mutable referenceQML: passing JS object to C++ member function

What rules turn any attack that hits a given target into a critical hit?

What kind of anatomy does a centaur have?

Do I care if the housing market has gone up or down, if I'm moving from one house to another?

Were the Apollo broadcasts recorded locally on the LM?

Does Impedance Matching Imply any Practical RF Transmitter Must Waste >=50% of Energy?

Why is DC so, so, so Democratic?

Wiring IKEA light fixture into old fixture

High income and difficulty during interviews

Can GPL and BSD licensed applications be used for government work?

What's the 1 inch size square knob sticking out of wall?

Book in which the "mountain" in the distance was a hole in the flat world

Would using carbon dioxide as fuel work to reduce the greenhouse effect?

I have a domain, static IP address and many devices I'd like to access outside my house. How do I route them?

Considerations when providing money to one child now, and the other later?

how to add 1 milliseconds on a datetime string?

Are rockets faster than airplanes?

How to run a substitute command on only a certain part of the line

How did pilots avoid thunderstorms and related weather before “reliable” airborne weather radar was introduced on airliners?

Company requiring me to let them review research from before I was hired

What is "It is x o'clock" in Japanese with subject

How can I show that the speed of light in vacuum is the same in all reference frames?

Why are Oscar, India, and X-Ray (O, I, and X) not used as taxiway identifiers?

How to apply dcolumn in my longtable case? Need help

On the history of Haar measure



How to “pull” data from c++ to qml?


What are the differences between a pointer variable and a reference variable in C++?How do I iterate over the words of a string?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListWhat is the effect of extern “C” in C++?What is the “-->” operator in C++?C++11 introduced a standardized memory model. What does it mean? And how is it going to affect C++ programming?Why is reading lines from stdin much slower in C++ than Python?How to pass data from QML to C++ as a mutable referenceQML: passing JS object to C++ member function






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I want "pull"data from c++ in qml like this:



 Component.onCompleted: 
MySettings.loadMainWindowPosition(aAppWnd.x, aAppWnd.y, aAppWnd.width, aAppWnd.height, aAppWnd.visibility);



When MySettings registered in the following way:



context->setContextProperty("MySettings", m_settings);


But when I make the funtion signature like this:



void MySettings::loadMainWindowPosition(int& x, int& y, int& width, int& height, int& visibility)


I received the following error:




qrc:/GUI/App.qml:35: Error: Unknown method parameter type: int&




So how correctly "pull" data inside qml from c++?



UPDATE:



I explain better. Now I can call the c++ function (and send params) from qml:



 Component.onCompleted: 
MySettings.someFunc(111, 222);



In c++ code I receive function call with params values "111" and "222".



But I want change this parameters in c++. I want smth like that:



 Component.onCompleted: 
var a;
var b;
MySettings.someFunc(a, b);



I want set up in the c++ code params to the "333" and "555". So after call MySettings.someFunc(a, b) I expected that (a==333) and (b==555).



How to do this?










share|improve this question



















  • 1





    You cannot pass a reference, this type isn't supported in js. See here for more info. Pass an object with properties instead and so update it in QML.

    – folibis
    Mar 26 at 16:50












  • @folibis could you please provide some example? I read your link but didnt get how to call c++ function that return values in params from qml :(

    – AeroSun
    Mar 26 at 20:40

















0















I want "pull"data from c++ in qml like this:



 Component.onCompleted: 
MySettings.loadMainWindowPosition(aAppWnd.x, aAppWnd.y, aAppWnd.width, aAppWnd.height, aAppWnd.visibility);



When MySettings registered in the following way:



context->setContextProperty("MySettings", m_settings);


But when I make the funtion signature like this:



void MySettings::loadMainWindowPosition(int& x, int& y, int& width, int& height, int& visibility)


I received the following error:




qrc:/GUI/App.qml:35: Error: Unknown method parameter type: int&




So how correctly "pull" data inside qml from c++?



UPDATE:



I explain better. Now I can call the c++ function (and send params) from qml:



 Component.onCompleted: 
MySettings.someFunc(111, 222);



In c++ code I receive function call with params values "111" and "222".



But I want change this parameters in c++. I want smth like that:



 Component.onCompleted: 
var a;
var b;
MySettings.someFunc(a, b);



I want set up in the c++ code params to the "333" and "555". So after call MySettings.someFunc(a, b) I expected that (a==333) and (b==555).



How to do this?










share|improve this question



















  • 1





    You cannot pass a reference, this type isn't supported in js. See here for more info. Pass an object with properties instead and so update it in QML.

    – folibis
    Mar 26 at 16:50












  • @folibis could you please provide some example? I read your link but didnt get how to call c++ function that return values in params from qml :(

    – AeroSun
    Mar 26 at 20:40













0












0








0








I want "pull"data from c++ in qml like this:



 Component.onCompleted: 
MySettings.loadMainWindowPosition(aAppWnd.x, aAppWnd.y, aAppWnd.width, aAppWnd.height, aAppWnd.visibility);



When MySettings registered in the following way:



context->setContextProperty("MySettings", m_settings);


But when I make the funtion signature like this:



void MySettings::loadMainWindowPosition(int& x, int& y, int& width, int& height, int& visibility)


I received the following error:




qrc:/GUI/App.qml:35: Error: Unknown method parameter type: int&




So how correctly "pull" data inside qml from c++?



UPDATE:



I explain better. Now I can call the c++ function (and send params) from qml:



 Component.onCompleted: 
MySettings.someFunc(111, 222);



In c++ code I receive function call with params values "111" and "222".



But I want change this parameters in c++. I want smth like that:



 Component.onCompleted: 
var a;
var b;
MySettings.someFunc(a, b);



I want set up in the c++ code params to the "333" and "555". So after call MySettings.someFunc(a, b) I expected that (a==333) and (b==555).



How to do this?










share|improve this question
















I want "pull"data from c++ in qml like this:



 Component.onCompleted: 
MySettings.loadMainWindowPosition(aAppWnd.x, aAppWnd.y, aAppWnd.width, aAppWnd.height, aAppWnd.visibility);



When MySettings registered in the following way:



context->setContextProperty("MySettings", m_settings);


But when I make the funtion signature like this:



void MySettings::loadMainWindowPosition(int& x, int& y, int& width, int& height, int& visibility)


I received the following error:




qrc:/GUI/App.qml:35: Error: Unknown method parameter type: int&




So how correctly "pull" data inside qml from c++?



UPDATE:



I explain better. Now I can call the c++ function (and send params) from qml:



 Component.onCompleted: 
MySettings.someFunc(111, 222);



In c++ code I receive function call with params values "111" and "222".



But I want change this parameters in c++. I want smth like that:



 Component.onCompleted: 
var a;
var b;
MySettings.someFunc(a, b);



I want set up in the c++ code params to the "333" and "555". So after call MySettings.someFunc(a, b) I expected that (a==333) and (b==555).



How to do this?







c++ qt qml qt5 qqmlcomponent






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 20:48







AeroSun

















asked Mar 26 at 14:29









AeroSunAeroSun

5641 gold badge6 silver badges30 bronze badges




5641 gold badge6 silver badges30 bronze badges







  • 1





    You cannot pass a reference, this type isn't supported in js. See here for more info. Pass an object with properties instead and so update it in QML.

    – folibis
    Mar 26 at 16:50












  • @folibis could you please provide some example? I read your link but didnt get how to call c++ function that return values in params from qml :(

    – AeroSun
    Mar 26 at 20:40












  • 1





    You cannot pass a reference, this type isn't supported in js. See here for more info. Pass an object with properties instead and so update it in QML.

    – folibis
    Mar 26 at 16:50












  • @folibis could you please provide some example? I read your link but didnt get how to call c++ function that return values in params from qml :(

    – AeroSun
    Mar 26 at 20:40







1




1





You cannot pass a reference, this type isn't supported in js. See here for more info. Pass an object with properties instead and so update it in QML.

– folibis
Mar 26 at 16:50






You cannot pass a reference, this type isn't supported in js. See here for more info. Pass an object with properties instead and so update it in QML.

– folibis
Mar 26 at 16:50














@folibis could you please provide some example? I read your link but didnt get how to call c++ function that return values in params from qml :(

– AeroSun
Mar 26 at 20:40





@folibis could you please provide some example? I read your link but didnt get how to call c++ function that return values in params from qml :(

– AeroSun
Mar 26 at 20:40












2 Answers
2






active

oldest

votes


















1














Don't try to get the return values as reference parameters when calling C++ functions from QML. Instead, use return values. To transfer more than one value in a single call, define your C++ method like



Q_INVOKABLE QVariantList someFunc() ... 


and use it in QML via



Component.onCompleted: 
var returnValues = MySettings.someFunc();
//access the returnValues via list indices here:
var a = returnValues[0];
var b = returnValues[1];






share|improve this answer






























    1














    Passing values ​​by reference do not work calling c ++ functions from QML. If you want sync calls, use something link this in your c ++ code:



    QVariantList MySettings::someFunc(int a, int b)

    QVariantList list;
    list.append(a + 5); // edit the passed values here
    list.append(b + 5); // edit the passed values here
    return list;



    and something like this in your QML code:



    var test = gapi.someFunc(3,2); // pass values here and get the new ones
    console.log("The return data" + test);





    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55359615%2fhow-to-pull-data-from-c-to-qml%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Don't try to get the return values as reference parameters when calling C++ functions from QML. Instead, use return values. To transfer more than one value in a single call, define your C++ method like



      Q_INVOKABLE QVariantList someFunc() ... 


      and use it in QML via



      Component.onCompleted: 
      var returnValues = MySettings.someFunc();
      //access the returnValues via list indices here:
      var a = returnValues[0];
      var b = returnValues[1];






      share|improve this answer



























        1














        Don't try to get the return values as reference parameters when calling C++ functions from QML. Instead, use return values. To transfer more than one value in a single call, define your C++ method like



        Q_INVOKABLE QVariantList someFunc() ... 


        and use it in QML via



        Component.onCompleted: 
        var returnValues = MySettings.someFunc();
        //access the returnValues via list indices here:
        var a = returnValues[0];
        var b = returnValues[1];






        share|improve this answer

























          1












          1








          1







          Don't try to get the return values as reference parameters when calling C++ functions from QML. Instead, use return values. To transfer more than one value in a single call, define your C++ method like



          Q_INVOKABLE QVariantList someFunc() ... 


          and use it in QML via



          Component.onCompleted: 
          var returnValues = MySettings.someFunc();
          //access the returnValues via list indices here:
          var a = returnValues[0];
          var b = returnValues[1];






          share|improve this answer













          Don't try to get the return values as reference parameters when calling C++ functions from QML. Instead, use return values. To transfer more than one value in a single call, define your C++ method like



          Q_INVOKABLE QVariantList someFunc() ... 


          and use it in QML via



          Component.onCompleted: 
          var returnValues = MySettings.someFunc();
          //access the returnValues via list indices here:
          var a = returnValues[0];
          var b = returnValues[1];







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 26 at 21:21









          MitjaMitja

          1,75922 silver badges26 bronze badges




          1,75922 silver badges26 bronze badges























              1














              Passing values ​​by reference do not work calling c ++ functions from QML. If you want sync calls, use something link this in your c ++ code:



              QVariantList MySettings::someFunc(int a, int b)

              QVariantList list;
              list.append(a + 5); // edit the passed values here
              list.append(b + 5); // edit the passed values here
              return list;



              and something like this in your QML code:



              var test = gapi.someFunc(3,2); // pass values here and get the new ones
              console.log("The return data" + test);





              share|improve this answer



























                1














                Passing values ​​by reference do not work calling c ++ functions from QML. If you want sync calls, use something link this in your c ++ code:



                QVariantList MySettings::someFunc(int a, int b)

                QVariantList list;
                list.append(a + 5); // edit the passed values here
                list.append(b + 5); // edit the passed values here
                return list;



                and something like this in your QML code:



                var test = gapi.someFunc(3,2); // pass values here and get the new ones
                console.log("The return data" + test);





                share|improve this answer

























                  1












                  1








                  1







                  Passing values ​​by reference do not work calling c ++ functions from QML. If you want sync calls, use something link this in your c ++ code:



                  QVariantList MySettings::someFunc(int a, int b)

                  QVariantList list;
                  list.append(a + 5); // edit the passed values here
                  list.append(b + 5); // edit the passed values here
                  return list;



                  and something like this in your QML code:



                  var test = gapi.someFunc(3,2); // pass values here and get the new ones
                  console.log("The return data" + test);





                  share|improve this answer













                  Passing values ​​by reference do not work calling c ++ functions from QML. If you want sync calls, use something link this in your c ++ code:



                  QVariantList MySettings::someFunc(int a, int b)

                  QVariantList list;
                  list.append(a + 5); // edit the passed values here
                  list.append(b + 5); // edit the passed values here
                  return list;



                  and something like this in your QML code:



                  var test = gapi.someFunc(3,2); // pass values here and get the new ones
                  console.log("The return data" + test);






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 28 at 17:50









                  Adriano CamposAdriano Campos

                  1911 silver badge6 bronze badges




                  1911 silver badge6 bronze badges



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55359615%2fhow-to-pull-data-from-c-to-qml%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                      Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                      Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript