Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can references or pointers be used in C++ methods called from QML/JavaScript?
Qt 6.11 is out! See what's new in the release blog

Can references or pointers be used in C++ methods called from QML/JavaScript?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 826 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
    SteveG
    wrote on last edited by
    #1

    Can references (or possibly pointers) be used when a C++ method is called from a JavaScript function in QML or can only values be used? For example, my code works when I have
    @
    MyClass{
    id: myclass
    }

    function mytest(){
    myclass.test(["Value1", "Value2", "Value3"]);
    }
    @

    in a QML file and
    @
    Q_INVOKABLE void test(QList<QString> arg);
    @

    in MyClass.h (with corresponding code in MyClass.cpp)

    but it generates an error when I use &arg or *arg.

    Must the return type of a C++ method also be a value or can references or pointers be used?

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

      You can use pointers to QObjects. I don't think any other would work, apart from standard const references (const QString &blah).

      (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