Return QtWebEngine 中 Q_INVOKABLE 函数的值
Return value from Q_INVOKABLE function In QtWebEngine
问候语
是否可以在不传递回调函数的情况下获取 Qt webEngine
中 Q_INVOKABLE
函数的 return 值? (Qt Documentation)。就像我们在 Qt WebKit
中所做的那样。
有关问题的更多信息
在 QT4
和 Qt WebKit
中,我可以将我的函数结果作为 QVariant
并将其转换为 JSON
或任何其他类型。
例如,在我的 C++ 项目中,我有以下函数,return 应用程序的版本为 QVariant
。
Q_INVOKABLE QVariant getAppVersion();
我可以简单地在我的 HTML
文件中使用以下行并获得结果。
var applicationVersion = ApplicationObject.getAppVersion();
现在使用 Qt 5.5
和 Qt WebEngine
我必须使用以下表格才能获得结果。
ApplicationObject.getAppVersion(myResultFunction);
function myResultFunction(result){
console.log(result);
}
我正在使用 QT 5.5
和 Visual Studio 2013
。
提前致谢
嗯,没有别的办法了。您必须通过 callback
函数。
但是在 javascript
中使用 promise
,它变得更好了!
祝你好运
问候语
是否可以在不传递回调函数的情况下获取 Qt webEngine
中 Q_INVOKABLE
函数的 return 值? (Qt Documentation)。就像我们在 Qt WebKit
中所做的那样。
有关问题的更多信息
在 QT4
和 Qt WebKit
中,我可以将我的函数结果作为 QVariant
并将其转换为 JSON
或任何其他类型。
例如,在我的 C++ 项目中,我有以下函数,return 应用程序的版本为 QVariant
。
Q_INVOKABLE QVariant getAppVersion();
我可以简单地在我的 HTML
文件中使用以下行并获得结果。
var applicationVersion = ApplicationObject.getAppVersion();
现在使用 Qt 5.5
和 Qt WebEngine
我必须使用以下表格才能获得结果。
ApplicationObject.getAppVersion(myResultFunction);
function myResultFunction(result){
console.log(result);
}
我正在使用 QT 5.5
和 Visual Studio 2013
。
提前致谢
嗯,没有别的办法了。您必须通过 callback
函数。
但是在 javascript
中使用 promise
,它变得更好了!
祝你好运