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. Calling static function through QMetaObject
QtWS25 Last Chance

Calling static function through QMetaObject

Scheduled Pinned Locked Moved Solved General and Desktop
qmetaobjectstatic methodinvokable
9 Posts 4 Posters 5.7k 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.
  • W Offline
    W Offline
    walteste
    wrote on last edited by
    #1

    Is there a way to invoke a static method of a class without supplying an object to the invokeMethod(...) of the QMetaObject?

    1 Reply Last reply
    0
    • jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Why do you want to use invokeMethod() to call a static method?

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

      W 1 Reply Last reply
      0
      • jsulmJ jsulm

        Why do you want to use invokeMethod() to call a static method?

        W Offline
        W Offline
        walteste
        wrote on last edited by
        #3

        @jsulm Well, because the method that I would like to invoke would not require an instance and therefore a static method is what I prefer. Is there any way to invoke a static method without an instance?

        The QMetaObkect::method(index) function also returns me the invokable static methods.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          hi
          Are we talking normal static functions?
          http://www.tutorialspoint.com/cplusplus/cpp_static_members.htm

          so you just call it like
          ClassName::static_method()
          ?

          W 1 Reply Last reply
          0
          • mrjjM mrjj

            hi
            Are we talking normal static functions?
            http://www.tutorialspoint.com/cplusplus/cpp_static_members.htm

            so you just call it like
            ClassName::static_method()
            ?

            W Offline
            W Offline
            walteste
            wrote on last edited by
            #5

            @mrjj Yes, a standard C++ static member function which is defined with Q_INVOKABLE. I will not only know at runtime which staticMetaObject I have to call this function. Therefore I can not use ClassName::static_method().

            mrjjM 1 Reply Last reply
            0
            • W walteste

              @mrjj Yes, a standard C++ static member function which is defined with Q_INVOKABLE. I will not only know at runtime which staticMetaObject I have to call this function. Therefore I can not use ClassName::static_method().

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @walteste
              Ok, so this is also regarding calling / make available to QML ? / scripting ?

              W 1 Reply Last reply
              0
              • mrjjM mrjj

                @walteste
                Ok, so this is also regarding calling / make available to QML ? / scripting ?

                W Offline
                W Offline
                walteste
                wrote on last edited by
                #7

                @mrjj Not necessarily, I just want sometimes to call a static function of different static meta objects without first using the newInstance to create an instance for performance reasons.

                1 Reply Last reply
                0
                • Chris KawaC Online
                  Chris KawaC Online
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  This is not possible with current API. Take a look at the generated moc_*.cpp file. The methods called via meta objects are always routed through YourClass::qt_static_metacall and it always takes an object pointer.

                  W 1 Reply Last reply
                  1
                  • Chris KawaC Chris Kawa

                    This is not possible with current API. Take a look at the generated moc_*.cpp file. The methods called via meta objects are always routed through YourClass::qt_static_metacall and it always takes an object pointer.

                    W Offline
                    W Offline
                    walteste
                    wrote on last edited by
                    #9

                    @Chris-Kawa Thanks for the information provided. Then I need to re-design my implementation accordingly to this limitation.

                    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