开发者

How to print a variable to Linux console using Javascript and QWebview

Inside a function which IS getting called through Qt's QWebView:

document.write ("11");

The above statement doesn't show anything on the console!

I want it to get displayed on the "console". I am running the qt executable as "./showmap" and then a widget gets displayed on which the map is shown. On a button click, a function gets called and开发者_StackOverflow in that function I have written document.write("11"); which doesn't seem to be doing anything normal.


That's what document.write does. It writes to the document.

To write to the OS's standard output or standard error, subclass QWebPage and override javascriptConsoleMessage.

Here is an example:

http://wiki.forum.nokia.com/index.php/Redirecting_JavaScript_console_messages_in_a_Qt_hybrid_application

Once you've overridden javascriptConsoleMessage to write to the operating system's stdout/stderr (with qDebug), calls to console.log will write to stdout/stderr as well.

As an alternative, overriding javascriptAlert() and then calling alert() in your Javascript should do the same thing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜