How to pass data from C++ application to Javascript

走远了吗. 提交于 2021-01-27 13:26:29

问题


I'm developing a jQuery-based pivot table.

The goal is not a web app but a desktop-based application (C++). In my idea, data is retrieved by the application from the database, then passed to a html page and then showed through the pivot-table plugin.

There is no web server and the web page containing the plugin cannot access to the database.

So, how to pass data in an efficient way? I've seen other questions here on SO around this matter, but I think we're in a different scenario. Of course I can write the data in a txt/xml/js file, but I've experienced that for huge amounts of data, writing down files is costing a lot.


回答1:


If you don't want to add support for the http protocol to your application, and you don't want to write to additional files, then IMO your best bet is to create a wrapping http server for your application. Then the javascript page can access the running wrapper which can talk to your "real" application.

You could create such a server relatively easily in python using the twisted framework, ruby using rails and the bundled webrick server, or the v8 Javascript engine node.js. (I'm sure there's dozens of other options out there too)

Which of there would be best for you will depend a lot on which languages you have experience with and what your deployment requirements are (supported OSes, existing installed applications, installation size, license terms on your software etc.)




回答2:


Do you have a specific framework for your desktop app ? If you use Qt for the GUI, you can also integrate javascript quite easily.

http://efforts.embedded.ufcg.edu.br/qt/?p=84




回答3:


You might be able to use named pipes to pass data to a static page.

It might also be better to just make your c++ program into a simple web server which opens a port, and have it generate the web page when the user goes to http://localhost:8080.



来源:https://stackoverflow.com/questions/5059147/how-to-pass-data-from-c-application-to-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!