为什么我会收到"QDeclarativeComponent:Component is not ready"错误?
Why do I get a "QDeclarativeComponent:Component is not ready" error?
我做了一些事情,但只停留在一个特定的例子中。代码类似
MyItem.qml
import QtQuick 1.0
Item {
function myQmlFunction(msg) {
console.log("Got message:", msg)
return "some return value"
}
}
main.cpp
QDeclarativeEngine engine;
QDeclarativeComponent component(&engine, "MyItem.qml");
QObject *object = component.create();
QVariant returnedValue;
QVariant msg = "Hello from C++";
QMetaObject::invokeMethod(object, "myQmlFunction",
Q_RETURN_ARG(QVariant, returnedValue),
Q_ARG(QVariant, msg));
qDebug() << "QML function returned:" << returnedValue.toString();
delete object;
这是一个简单的例子,但当我在qt(5.0)中运行此代码时,它会显示如下内容QDeclarativeComponent:组件尚未就绪。
我知道我错过了什么。在谷歌上,我发现这个方法应该声明为Q_INVOKABLE,但我不明白为什么?
在QML中创建组件时,第一步是解析QML文件。这就是当您调用时发生的情况:
QDeclarativeComponent component(&engine, "MyItem.qml");
然后,在调用QDeclarativeComponent::create
之前,您必须等待组件状态传递给Ready
。您可以通过处理状态更改信号来跟踪状态更改。
一旦组件准备就绪,就创建组件实例。
相关文章:
- Directx 11 - CompileFromFile() is not compiling
- Centos7 g++ "to_string is not in a member of std"
- 将成员函数作为构造函数参数调用时出错 "Variable is not a type name"
- reference_wrapper导致"incomplete type is not allowed"
- 结构中的错误"Incomplete type is not allowed"
- "Called Object Type is Not a Function or Pointer" 与 typedef 和类
- 无法创建 DLL:获取 DLL "is not a valid Win32 application"
- Atom gpp编译器给出"'C:UsersadminUser' is not recognized as an internal or..."错误
- 当我编译XG-Bosst时,出现错误"error: 'Split' is not a member of 'xgboost::common' ……"
- C++ DLL 运行时错误"abc.dll is not a valid WIN32 application" 。请帮助解决这个问题
- 如何修复 eigen3 中的'non-type template argument is not a constant expression'?
- 我的代码应该接受一个数字,并返回字母等级或"Grade is not valid"但 else 语句不起作用
- 如何修复此错误"the value of 'x1' is not usable in a constant expression"?static_assert
- 加载安全区图像"A device attached to the system is not functioning"
- 巴泽尔中的错误"name 'new_local_repository' is not defined"
- 如何修复 SDL2 "GLSL 3.30 is not supported"错误
- 函数模板(它是类模板的成员)的显式专用化会产生"partial specialization is not allowed"错误,为什么?
- 为什么"an inherited constructor is not a candidate for initialization from an expression of the same or
- CGAL 绘制函数在 Visual Studio 中给出'CGAL_USE_BASIC_VIEWER is not defined'错误
- "OpenCV Error: The function/feature is not implemented"安卓应用程序