Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. C function as QJSValue
Forum Updated to NodeBB v4.3 + New Features

C function as QJSValue

Scheduled Pinned Locked Moved Unsolved Language Bindings
5 Posts 2 Posters 1.0k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    skylendar
    wrote on last edited by skylendar
    #1

    Hi there and thx for answering if you can.

    In my QJS scripts, I need to call C functions but it is not clear in the doc how to declare such an operation. i.e.

    int myfunc(int a, int b);
    
     QJSValue myFunction = myEngine.newObject();
     myFunction.setProperty("myfunc", myfunction);
    

    then...

    Thx again for answering.

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

      Hi
      You do the same as a c++ function.
      https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html
      example.
      https://forum.qt.io/topic/33170/call-c-function-from-qml

      the c++ function can then call the C function.

      1 Reply Last reply
      1
      • S Offline
        S Offline
        skylendar
        wrote on last edited by
        #3

        Ok, it works with C++ classes, but I just want to bind a c function with a QJSValue, making it callable

        mrjjM 1 Reply Last reply
        0
        • S skylendar

          Ok, it works with C++ classes, but I just want to bind a c function with a QJSValue, making it callable

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

          Hi
          I dont think its possible that way you try.

          https://doc.qt.io/qt-5/qtqml-cppintegration-topic.html
          https://doc.qt.io/qt-5/qtqml-cppintegration-overview.html#

          I dont see any samples of using plain function pointers and its
          very doubtful that the JS could just call it any way.

          Just use the QObject way. Its like 12 lines of code extra.

          1 Reply Last reply
          1
          • S Offline
            S Offline
            skylendar
            wrote on last edited by
            #5

            So I give up. I'll declare a method instead.

            Maybe in a further version of Qt5.

            Thank you anyway.

            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