Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [Solved]qml can not recognize the c++ parameters with &
Forum Updated to NodeBB v4.3 + New Features

[Solved]qml can not recognize the c++ parameters with &

Scheduled Pinned Locked Moved QML and Qt Quick
11 Posts 2 Posters 6.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sierdzio
    Moderators
    wrote on 25 Jun 2013, 06:42 last edited by
    #2

    Data will be copied anyway, as JavaScript lists and QList are different. It does seem a bit strange, though, especially the part about using only one parameter.

    Try usign QVariant, maybe? And then getting the data using QVariant::value<>().

    (Z(:^

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stereomatching
      wrote on 25 Jun 2013, 06:59 last edited by
      #3

      [quote author="sierdzio" date="1372142579"]
      Try usign QVariant, maybe? And then getting the data using QVariant::value<>().[/quote]

      QVariant can prevent the copy of the data?
      Could you show me an example?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sierdzio
        Moderators
        wrote on 25 Jun 2013, 07:03 last edited by
        #4

        It might, although it probably won't. I was rather thinking about allowing you to use 2 parameters.

        (Z(:^

        1 Reply Last reply
        0
        • S Offline
          S Offline
          stereomatching
          wrote on 25 Jun 2013, 07:19 last edited by
          #5

          Do we have a way to pass heavy data between qml and c++ without copy?

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sierdzio
            Moderators
            wrote on 25 Jun 2013, 07:22 last edited by
            #6

            By using QObject pointers.

            For me, const QString references and QLists of pointers also do work. I don't know the internals of the engine well enough to answer your question with confidence.

            (Z(:^

            1 Reply Last reply
            0
            • S Offline
              S Offline
              stereomatching
              wrote on 25 Jun 2013, 07:32 last edited by
              #7

              [quote author="sierdzio" date="1372144978"]By using QObject pointers.

              For me, const QString references and QLists of pointers also do work. I don't know the internals of the engine well enough to answer your question with confidence.[/quote]

              Could you show me some example?

              1 Reply Last reply
              0
              • S Offline
                S Offline
                sierdzio
                Moderators
                wrote on 25 Jun 2013, 07:35 last edited by
                #8
                • "link":https://github.com/sierdzio/closecombatfree/blob/master/src/ccfgamemanager.h
                • "link":https://github.com/sierdzio/closecombatfree/blob/master/src/logic/ccfenginehelpers.h
                • and "link":https://github.com/sierdzio/closecombatfree/blob/master/src/logic/ccfscenariostate.h

                Feel free to check out the whole project, it can easily be browsed in Qt Creator.

                (Z(:^

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  stereomatching
                  wrote on 25 Jun 2013, 07:38 last edited by
                  #9

                  Thanks for your help.

                  Since a lot of heavy jobs would be done on c++ sites, I hope in the future we could
                  pass the parameters between c++ and qml by reference.

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    stereomatching
                    wrote on 25 Jun 2013, 08:14 last edited by
                    #10

                    Can't find a reasonable way to transform between string and QObject
                    so I try const&

                    @
                    /**

                    • @brief find out the different string of new_data compare with the old data
                    • @param old_data : the old data
                    • @param new_data : the new data
                    • @return the combination of the old data and the different string of new_data compare with the old data
                    • @example old_data = {1, 2, 3, 4}, new_data = {1, 3, 4, 5}, results = {1, 2, 3, 4, 5}
                    • @caution : qml site could not recognize the parameters with &(even it can, it still copy the parameters rather than take the reference)
                    •        pass the parameters by const& seems work, but I am not sure it would not copy the data by this way
                      

                    */
                    QList<QString> fileProcess::unique_strs(QList<QString> const &old_data, QList<QString> const &new_data)
                    {
                    //awkward solution and maybe meaningless, hope that in the future this could be solved
                    return set_difference_lazy(const_cast<QList<QString>&>(new_data), const_cast<QList<QString>&>(old_data));
                    }
                    @

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      stereomatching
                      wrote on 25 Jun 2013, 15:37 last edited by
                      #11

                      After some experiment, the last post of my solution is useless, the data of
                      qml and c++ are always copy

                      1 Reply Last reply
                      0

                      11/11

                      25 Jun 2013, 15:37

                      • Login

                      • Login or register to search.
                      11 out of 11
                      • First post
                        11/11
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved