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. Detect when C++ method called from QML. How?
Forum Updated to NodeBB v4.3 + New Features

Detect when C++ method called from QML. How?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 340 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.
  • B Offline
    B Offline
    bogong
    wrote on last edited by
    #1

    Hello all!
    Is there any way to detect that method called from QML? I have the public slot that implemented in C++ class and it's might be called from QML and sometimes directly from C++.
    The method C++ code:

    public slots:
    		void mSomeMethod(sometype inSomeValue);
    ...
    pRootContext->setContextProperty("SomeObject",pSomeObject);
    

    The calling from QML:

    SomeObject.mSomeMethod(inSomeValue);
    

    The calling from C++:

    pSomeObject->mSomeMethod(inSomeValue);
    

    The question is how to detect that method called from QML or C++? Is there any way without additional parameter?

    KroMignonK 1 Reply Last reply
    0
    • B bogong

      Hello all!
      Is there any way to detect that method called from QML? I have the public slot that implemented in C++ class and it's might be called from QML and sometimes directly from C++.
      The method C++ code:

      public slots:
      		void mSomeMethod(sometype inSomeValue);
      ...
      pRootContext->setContextProperty("SomeObject",pSomeObject);
      

      The calling from QML:

      SomeObject.mSomeMethod(inSomeValue);
      

      The calling from C++:

      pSomeObject->mSomeMethod(inSomeValue);
      

      The question is how to detect that method called from QML or C++? Is there any way without additional parameter?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @bogong said in Detect when C++ method called from QML. How?:

      Is there any way without additional parameter?

      No, you are calling a method from a C++ instance, like you would do it with any C++ instance.
      You can also not know which C++ instance would call this method.

      If you need to know it, you have 2 options:

      • add a parameter to describe source
      • create a specific function for QML

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      B 1 Reply Last reply
      3
      • KroMignonK KroMignon

        @bogong said in Detect when C++ method called from QML. How?:

        Is there any way without additional parameter?

        No, you are calling a method from a C++ instance, like you would do it with any C++ instance.
        You can also not know which C++ instance would call this method.

        If you need to know it, you have 2 options:

        • add a parameter to describe source
        • create a specific function for QML
        B Offline
        B Offline
        bogong
        wrote on last edited by
        #3

        @KroMignon Thx. Issue closed. Will do parameter like always.

        1 Reply Last reply
        1

        • Login

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