Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. JavaScript types in C++
QtWS25 Last Chance

JavaScript types in C++

Scheduled Pinned Locked Moved Qt WebKit
5 Posts 3 Posters 5.0k 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.
  • K Offline
    K Offline
    kyrie
    wrote on last edited by
    #1

    Hi all!

    I have a number of JavaScript events (like MouseMoved, etc.), which brings as parameter some JavaScript type (like JSPoint, for example). I want to emit C++ signals from JavaScript code, so I install object using addToJavaScriptWindowObject() with a number of signals, and then simply call them in js code. Everything works fine for build-in types like QString.
    Question: how can I instruct Qt to perform auto-conversion for the signal arguments types? For example, I want to create C++ type CPoint, and I want Qt to convert JSPoint to CPoint when I emit signal.
    I think that this problem may be solved using QMetaType - register new type - but what else? I found articles in documentation, but they tell how to make C++ object accessible in script envirinment (js or Qt script).

    Any ideas?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      danilocesar
      wrote on last edited by
      #2

      Can you transform them to json objects?

      They will be recognized by c++ as QVariantMap.

      <a href="http://www.danilocesar.com">Danilo Cesar Lemes de Paula</a>
      Software Engineer

      1 Reply Last reply
      0
      • B Offline
        B Offline
        benjamin.poulain
        wrote on last edited by
        #3

        bq. For example, I want to create C++ type CPoint, and I want Qt to convert JSPoint to CPoint when I emit signal.

        This is not possible. Think about it, how would we implement that?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kyrie
          wrote on last edited by
          #4

          As 'fixme' solution I use conversion to string before emit, then emit QString, and then decode data from string. I am lucky that all JavaScript types what I need have 'toString()' method.
          Conversion to json objects is not suitable, but I knew nothing about this variant, thanks a lot.
          Concerning the possible implementation, quick dirty idea is to allow conversion to those types which are registered in Qt metatype system. Valid type is selected according to name comparison. The same way we select qt property in C++ object correspondent to js object field: field name comparison. But before generating ideas -) , it's better to find how Qt now supports conversion between some build-in types, for example - QString - I don't know how it was done.

          Thanks to all.

          1 Reply Last reply
          0
          • B Offline
            B Offline
            benjamin.poulain
            wrote on last edited by
            #5

            bq. it’s better to find how Qt now supports conversion between some build-in types, for example – QString – I don’t know how it was done.

            Here is the code:
            "http://gitorious.org/webkit/qtwebkit/blobs/qtwebkit-2.1/WebCore/bridge/qt/qt_runtime.cpp":http://gitorious.org/webkit/qtwebkit/blobs/qtwebkit-2.1/WebCore/bridge/qt/qt_runtime.cpp

            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