Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Calling static function through QMetaObject

    General and Desktop
    qmetaobject static method invokable
    4
    9
    4809
    Loading More Posts
    • 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
      walteste last edited by

      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 Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • W
          walteste @jsulm last edited by

          @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 Reply Quote 0
          • mrjj
            mrjj Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • W
              walteste @mrjj last edited by

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

              mrjj 1 Reply Last reply Reply Quote 0
              • mrjj
                mrjj Lifetime Qt Champion @walteste last edited by

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

                W 1 Reply Last reply Reply Quote 0
                • W
                  walteste @mrjj last edited by

                  @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 Reply Quote 0
                  • Chris Kawa
                    Chris Kawa Moderators last edited by

                    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 Reply Quote 1
                    • W
                      walteste @Chris Kawa last edited by

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

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post