Based on QT QWebEnginePage::setWebChannel() transport object and Qt: Cannot invoke shared object methods/properties from javascript I tried to make a small demo to test the
I had the same issue recently. After some investigation, I figured out how to make it work. Big thanks to the answer of this question: How to use Qt WebEngine and QWebChannel?
In order to get the return value of a method of your QObject, you need to define a Q_PROPERTY wrapping your QObject method. For example:
class SharedObject : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE int getIntValue();
Q_PROPERTY(int intValue READ getIntValue)
Q_INVOKABLE QString getStringValue();
Q_PROPERTY(QString stringValue READ getStringValue)
}
And then in your HTML, do this:
You should be able to see intValue and stringValue in your JavaScript code. The important bit is to use Q_PROPERTY I think.
Anyway, this resolves my problem, and I hope it helps for someone else too.