3

According to http://doc.qt.io/qt-5/qtwebchannel-javascript.html

Furthermore keep in mind that only QML/C++ data types which can be converted to JSON will be (de-)serialized properly and thus accessible to HTML clients.

What are those data types which can be converted to JSON? Is the QJsonObject or QJsonDocument included on it?

Daniel Santos
  • 14,328
  • 21
  • 91
  • 174
  • 1
    The web page says > The transport object implements a minimal message passing interface. > It should be an object with a send() function, which takes a > stringified JSON message and transmits it to the server-side It would appear you have to roll your own JSON and send it to and from the server. – Jimmy Feb 11 '16 at 18:10
  • Qt provices a propper wrapper. But something happens before it that takes the raw data (int, string, etc) and transforms it in a QJson object to send it later using the wrapper. – Daniel Santos Feb 11 '16 at 19:07

1 Answers1

1

You can look into the documentation for classes such as QJsonValue and QJsonObject and see which types and classes can be used by constructors or by from*(...) functions, which are usually static and ask for a QVariant/QVariantHash/QVariantMap.

Given that in Qt JavaScript an array can be converted into a QList<> and an object to a QVariantMap, I would guess those (and basic types such as int, float, string...) should be passed to the C++ side and made into QJson(Value/Object/Array) then.

Depending on what you want, a QJsonObject could be, for example, formatted as a string like this. For further information, JSON support in Qt.

Community
  • 1
  • 1
Abdiel
  • 81
  • 1
  • 5