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 22 Feb 2016, 12:58 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
    • J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 22 Feb 2016, 13:07 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 22 Feb 2016, 18:40
      0
      • J jsulm
        22 Feb 2016, 13:07

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

        W Offline
        W Offline
        walteste
        wrote on 22 Feb 2016, 18:40 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
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 22 Feb 2016, 18:45 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 22 Feb 2016, 18:48
          0
          • M mrjj
            22 Feb 2016, 18:45

            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 22 Feb 2016, 18:48 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().

            M 1 Reply Last reply 22 Feb 2016, 18:55
            0
            • W walteste
              22 Feb 2016, 18:48

              @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().

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 22 Feb 2016, 18:55 last edited by
              #6

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

              W 1 Reply Last reply 22 Feb 2016, 18:58
              0
              • M mrjj
                22 Feb 2016, 18:55

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

                W Offline
                W Offline
                walteste
                wrote on 22 Feb 2016, 18:58 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
                • C Offline
                  C Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on 22 Feb 2016, 20:56 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 23 Feb 2016, 05:08
                  1
                  • C Chris Kawa
                    22 Feb 2016, 20:56

                    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 23 Feb 2016, 05:08 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

                    1/9

                    22 Feb 2016, 12:58

                    • 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