Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-139095

I want to return data to Java/Kotlin from my QML functions

XMLWordPrintable

    • Icon: User Story User Story
    • Resolution: Unresolved
    • Icon: Not Evaluated Not Evaluated
    • None
    • None
    • QPA: Android

      As a user of the QtQuickViewContent / QtQuickView API, some of the QML functions I define may need to return values when called. Right now, the function API introduced by QTBUG-137112 does not support this.

       

      Possible implementation:

      1. qtbase androiddeployqt:
        1. Figure out a way to detect the QML type returned by a QML function via qmldom
        2. Generate the correct signature for QtQuickViewContent types
        3. Generate the method implementation in QtQuickViewContent-descendant type, that will call the QtQuickView implementation defined below.
      2. qtdeclarative:
        1. Provide a typed (Object only or Integer+Double+Float+...other types) API to QtQuickView.java to call functions that return values
        2. Provide support on the JNI interface for types - a single function that returns Object is sufficient, just convert from Object to necessary Type when returning the value to user
          1. e.g. native method: Object invokeMethod(args)
          2. usage:
            • Integer callIntFunction() { return (Integer) invokeMethod(args); }
            • note: explicitly casting may not be necessary, java probably does it automatically.
        3. On the C++ side, extend the current function invocation implementation to also accept a return value, convert the return value to QVariant (probably from QJSValue?), and then convert the QVariant's internal data into a Object type, returning it from the native call.
          1. This may need some synchronization, maybe waiting for the QML function to be invoked on the main Qt thread, so QFuture or something. 

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            qtandroidteam Qt Android Team
            pevirkku Petri Virkkunen
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes