Qt: Throwing an exception from C++ to QML engine
<p>When calling a <code>Q_INVOKABLE</code> method written in <code>C++</code> from a <code>JavaScript</code> function in <code>QML</code>, how do you throw an exception ? The method is owned by an object of a type <code>&lt; MyApp &gt;</code> , registered with a call <code>qmlRegisterType()</code></p>

<p>For example, I have the following QML code:</p>

<pre><code>TextField {
    id: fld_recipient

    onEditingFinished: {
        try {
            var identity=myapp.identities.current_Identity;
            var company=identity.companies.current_Company;
            myapp.lookup_email(identity.identity_id,company.company_id,fld_recipient.text)
        } catch(e) {
            console.log(e);
        }
    }
}
</code></pre>

<p>Here, the method MyApp::lookup_email() goes to the server and searches for matching email addresses. This process can be stopped by a large amount of errors and I want the catch() statement to show that error. </p>

<p>How is this done on the C++ side ? Kind of like this:</p>

<pre><code>void MyApp::lookup_email(int identity_id,int company_id,QString email) {

    ....

    error_code=server-&gt;lookup_email(identity_id,company_id,email);

    if (error_code) { /// throw an exception to QML engine, 
         ????? &lt;= what goes here ?
    }
}
</code></pre>