Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Calling from C++ Java method which returns List<int[]>
Forum Updated to NodeBB v4.3 + New Features

Calling from C++ Java method which returns List<int[]>

Scheduled Pinned Locked Moved Solved Mobile and Embedded
c++javaandroid
9 Posts 3 Posters 4.1k 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.
  • R Offline
    R Offline
    Ruslan Baratov
    wrote on 5 Feb 2016, 14:39 last edited by
    #1

    Hi,

    I'm trying to call getSupportedPreviewFpsRange Java method from C++. This method has signature List<int[]> getSupportedPreviewFpsRange () so first I do:

    QJNIObjectPrivate rangeListNative = m_parameters.callObjectMethod("getSupportedPreviewFpsRange", "()Ljava/util/List;");
    

    which returns valid object. Then I try to call get method to access jintArray (?).

    Got undefined reference error:

    rangeListNative.callMethod<jintArray>("get", "(I)[I", i);
    

    Method not found error:

    rangeListNative.callObjectMethod<jintArray>("get", "(I)[I", i);
    

    Returns null pointer:

    rangeListNative.callObjectMethod("get", "(I)[I", i);
    

    What is the right way to do it?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Carmoneer
      wrote on 5 Feb 2016, 16:24 last edited by
      #2

      I have a similar method signature that I use for Android. I have no idea if this will be beneficial for you or not...
      Possibly replace "(I)Ljava/lang/Object" with "(I)Ljava/lang/List"

      QAndroidJniObject jResult =resultsVector.callObjectMethod("get", "(I)Ljava/lang/Object;", i);
      
      R 1 Reply Last reply 5 Feb 2016, 16:34
      1
      • C Carmoneer
        5 Feb 2016, 16:24

        I have a similar method signature that I use for Android. I have no idea if this will be beneficial for you or not...
        Possibly replace "(I)Ljava/lang/Object" with "(I)Ljava/lang/List"

        QAndroidJniObject jResult =resultsVector.callObjectMethod("get", "(I)Ljava/lang/Object;", i);
        
        R Offline
        R Offline
        Ruslan Baratov
        wrote on 5 Feb 2016, 16:34 last edited by
        #3

        @Carmoneer but how can I get value for jintArray from it? is it a correct way:

        QJNIObjectPrivate jRange =resultsVector.callObjectMethod("get", "(I)Ljava/lang/Object;", i);
        jintArray jRange = static_cast<jintArray>(range.object());
        

        ?

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Ruslan Baratov
          wrote on 5 Feb 2016, 16:46 last edited by
          #4

          Actually it works :) Here is a full code snippet:

          QJNIObjectPrivate rangeListNative = m_parameters.callObjectMethod("getSupportedPreviewFpsRange", "()Ljava/util/List;");
          int count = rangeListNative.callMethod<jint>("size");
          for (int i = 0; i < count; ++i) {
              QJNIObjectPrivate range = rangeListNative.callObjectMethod("get", "(I)Ljava/lang/Object;", i);
          
              jintArray jRange = static_cast<jintArray>(range.object());
              jint* rangeArray = env->GetIntArrayElements(jRange, 0);
          
              AndroidCamera::FpsRange fpsRange;
          
              /* int */ fpsRange.min = rangeArray[0];
              /* int */ fpsRange.max = rangeArray[1];
          
              env->ReleaseIntArrayElements(jRange, rangeArray, 0);
          
              rangeList << fpsRange;
          }
          

          wonder if it's correct (?).

          B 1 Reply Last reply 6 Feb 2016, 16:50
          0
          • C Offline
            C Offline
            Carmoneer
            wrote on 5 Feb 2016, 16:51 last edited by
            #5

            Oh, great! Glad to hear it is working. :) Everything looks good to me, however, I am certainly no expert.

            1 Reply Last reply
            0
            • R Ruslan Baratov
              5 Feb 2016, 16:46

              Actually it works :) Here is a full code snippet:

              QJNIObjectPrivate rangeListNative = m_parameters.callObjectMethod("getSupportedPreviewFpsRange", "()Ljava/util/List;");
              int count = rangeListNative.callMethod<jint>("size");
              for (int i = 0; i < count; ++i) {
                  QJNIObjectPrivate range = rangeListNative.callObjectMethod("get", "(I)Ljava/lang/Object;", i);
              
                  jintArray jRange = static_cast<jintArray>(range.object());
                  jint* rangeArray = env->GetIntArrayElements(jRange, 0);
              
                  AndroidCamera::FpsRange fpsRange;
              
                  /* int */ fpsRange.min = rangeArray[0];
                  /* int */ fpsRange.max = rangeArray[1];
              
                  env->ReleaseIntArrayElements(jRange, rangeArray, 0);
              
                  rangeList << fpsRange;
              }
              

              wonder if it's correct (?).

              B Offline
              B Offline
              benlau
              Qt Champions 2016
              wrote on 6 Feb 2016, 16:50 last edited by
              #6

              @Ruslan-Baratov said:

              wonder if it's correct (?).

              I just use the "get" method. Not sure is your method "correct", but it looks fine.

              My code:
              https://github.com/benlau/quickandroid/blob/master/qasystemdispatcher.cpp#L41

              R 1 Reply Last reply 7 Feb 2016, 16:12
              1
              • B benlau
                6 Feb 2016, 16:50

                @Ruslan-Baratov said:

                wonder if it's correct (?).

                I just use the "get" method. Not sure is your method "correct", but it looks fine.

                My code:
                https://github.com/benlau/quickandroid/blob/master/qasystemdispatcher.cpp#L41

                R Offline
                R Offline
                Ruslan Baratov
                wrote on 7 Feb 2016, 16:12 last edited by
                #7

                I just use the "get" method

                @benlau I use "get" method too but only for Java object. As far as I understand element of the list is not a Java object, it's integer array int[].

                B 1 Reply Last reply 7 Feb 2016, 23:59
                0
                • R Ruslan Baratov
                  7 Feb 2016, 16:12

                  I just use the "get" method

                  @benlau I use "get" method too but only for Java object. As far as I understand element of the list is not a Java object, it's integer array int[].

                  B Offline
                  B Offline
                  benlau
                  Qt Champions 2016
                  wrote on 7 Feb 2016, 23:59 last edited by
                  #8

                  @Ruslan-Baratov said:

                  I just use the "get" method

                  @benlau I use "get" method too but only for Java object. As far as I understand element of the list is not a Java object, it's integer array int[].

                  Everything in Java is an object. Regardless of the actual storage method , List<T> is in fact an array of java.lang.Object, but you could use it like an int[] .

                  R 1 Reply Last reply 8 Feb 2016, 10:53
                  1
                  • B benlau
                    7 Feb 2016, 23:59

                    @Ruslan-Baratov said:

                    I just use the "get" method

                    @benlau I use "get" method too but only for Java object. As far as I understand element of the list is not a Java object, it's integer array int[].

                    Everything in Java is an object. Regardless of the actual storage method , List<T> is in fact an array of java.lang.Object, but you could use it like an int[] .

                    R Offline
                    R Offline
                    Ruslan Baratov
                    wrote on 8 Feb 2016, 10:53 last edited by
                    #9

                    Everything in Java is an object

                    @benlau Okay, thanks for the information. Good to know :)

                    1 Reply Last reply
                    0

                    1/9

                    5 Feb 2016, 14:39

                    • Login

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