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. Can Q_INVOKABLE function return reference ?
Forum Updated to NodeBB v4.3 + New Features

Can Q_INVOKABLE function return reference ?

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 3 Posters 6.4k 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.
  • A Offline
    A Offline
    aabc
    wrote on last edited by
    #1

    Can Q_INVOKABLE function return reference ?

    For example: Q_INVOKABLE const QString& myFunc(int _myInt);

    1 Reply Last reply
    0
    • W Offline
      W Offline
      warjan
      wrote on last edited by
      #2

      I don't see any mention in the docs it can't. Check whether it works then you'll know it for sure.

      Does your grass is really that greener?

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        I notice you post it in QtQuick subforum. Remember that Q_INVOKABLE is just a first step in passing a value to QML. Even if that works, conversion in QML engine might not. Also good to bare in mind is the fact that QString is implicitly shared, so maybe a standard QString return would do without performance penalty.

        Best course of action is - as warjan suggested - to try it out. Please post your results here if you don't mind :)

        (Z(:^

        1 Reply Last reply
        0
        • W Offline
          W Offline
          warjan
          wrote on last edited by
          #4

          I second sierdzio's request for you, aabc to post about your findings.

          Offtopic: Damn, I'm so used to giving feedback in form of +1 or Like that I miss those here.

          Does your grass is really that greener?

          1 Reply Last reply
          0
          • A Offline
            A Offline
            aabc
            wrote on last edited by
            #5

            I will test it

            1 Reply Last reply
            0
            • W Offline
              W Offline
              warjan
              wrote on last edited by
              #6

              After some more reading I can bet that you can use Q_INVOKEABLE with function returning references and you can't do it for QML and C++ data exchange, because data is transferred between those in QVariant and it can't hold references if I understand it correctly.

              http://doc.qt.digia.com/qt/qtbinding.html#exchanging-data-between-qml-and-c
              http://doc.qt.digia.com/qt/qvariant.html#Type-enum

              Does your grass is really that greener?

              1 Reply Last reply
              0
              • A Offline
                A Offline
                aabc
                wrote on last edited by
                #7

                "you can’t do it for QML and C++ data exchange"

                For what other reason should I use Q_INVOKEABLE ?

                1 Reply Last reply
                0
                • W Offline
                  W Offline
                  warjan
                  wrote on last edited by
                  #8

                  AFAIK it's used for slot and signals mechanism and then some http://qt-project.org/doc/qt-4.8/qmetaobject.html#details you can call invokeMethod on Q_INVOKEABLE functions.

                  Does your grass is really that greener?

                  1 Reply Last reply
                  0
                  • sierdzioS Offline
                    sierdzioS Offline
                    sierdzio
                    Moderators
                    wrote on last edited by
                    #9

                    [quote author="aabc" date="1358336600"]"you can’t do it for QML and C++ data exchange"
                    For what other reason should I use Q_INVOKEABLE ?[/quote]

                    There are all sorts of uses outside QML. This macro is much older than QML and is part of the Meta-Object system.

                    (Z(:^

                    1 Reply Last reply
                    0

                    • Login

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