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. How can I call object method inside static method
Forum Updated to NodeBB v4.3 + New Features

How can I call object method inside static method

Scheduled Pinned Locked Moved Solved Mobile and Embedded
2 Posts 2 Posters 158 Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    hi, i can successfully call my android java functions from c++. and I get callback this functions like this.

    Java Native Method

    public native void vpnStatusChanged(String status);
    

    C++ area
    8628a17f-aad3-47cc-bfe8-703f6d46c3c6-image.png

    I can successfully print the incoming value to the screen. But I can't call these methods

    setVpnStatus()

    jsulmJ 1 Reply Last reply
    0
    • ? A Former User

      hi, i can successfully call my android java functions from c++. and I get callback this functions like this.

      Java Native Method

      public native void vpnStatusChanged(String status);
      

      C++ area
      8628a17f-aad3-47cc-bfe8-703f6d46c3c6-image.png

      I can successfully print the incoming value to the screen. But I can't call these methods

      setVpnStatus()

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @NullByte said in How can I call object method inside static method:

      But I can't call these methods

      You need the instance of that class.
      There are different ways to do this. One is to make this class a singleton. Or you simply put a pointer variable of type Android* in the cpp file and assign it in the constructor:

      Android *instance{nullptr};
      
      Android::Android(...)
      {
          instance = this;
      }
      
      void Android::onVPNStatusChanged(...)
      {
          if (instance)
              instance->setVpnStatus...
      }
      

      And please post code as text, not images. Code is text.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • System has marked this topic as solved on

      • Login

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