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. How to send an exception to the JavaScript context?

How to send an exception to the JavaScript context?

Scheduled Pinned Locked Moved Qt WebKit
1 Posts 1 Posters 2.9k 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.
  • J Offline
    J Offline
    jampy81
    wrote on last edited by
    #1

    I have a simple Qt 4.7 application that uses QtWebKit to display a HTML/JavaScript page. Using addToJavaScriptWindowObject() a few C++ functions are provided to the JavaScript environment.

    Is there a way to raise an exception in the JavaScript context in certain situations when such an exported C++ function is called from JavaScript?

    • Throwing a C++ exception, like { throw 123; }, simply crashes the Qt application
    • Using @m_view->page()->mainFrame()->evaluateJavaScript("throw new Error('whatever');")@ I can throw an exception but apparently it is not being passed to the calling JavaScript context (i.e. just the eval() code itself is being aborted)

    Looking at the source code I see methods like setException() and similar but apparently I need a JSContext or some other reference to the calling JavaScript context, but I have no clue how to get it (there is no such thing in QWebFrame although WebKit itself or QWebFramePrivate seem to have such a reference).

    My final goal is that a JavaScript code like

    @try {
    specialBrowserObject.someFunction();
    } catch (e) {
    document . write("Exception: "+e.message);
    }@

    shows the exception created in C++ (specialBrowserObject being the object exposed via addToJavaScriptWindowObject()).

    Any suggestions?

    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