解析JavaScript QML项目至C QT
Parse JavaScript QML item to C++ QT
我在qml中具有JavaScript函数,该功能创建和返回组件(Item
(:
function addMyComponent() {
var component = Qt.createComponent('MyComponent.qml');
var obj = component.createObject(container, {'x': 0, 'y': 0});
return obj; // Not sure weather to return obj or component for my C++ to use
}
我在main.qml
中也有一些QML,它使用了我制作的自定义C 类:
// ...
import com.acidic.customclass 1.0
import "AddMyComponent.js" as AddMyComponent
ApplicationWindow {
visible: true
width: 1280
height: 800
CustomClass {
id: customClass
}
Button {
onClicked: {
customClass.receiveComponent(AddMyComponent.addMyComponent)
}
}
}
和我的C 类标题:
Q_INVOKABLE void receiveComponent(const QObject& obj /* QObject ref doesn't work */);
和身体:
void CustomClass::receiveComponent(const QObject& obj) {
qDebug(obj.property("width")); // To see if we have received it correctly
}
如何将用JavaScript创建的组件和Qt.createComponent
解析到我的自定义C 类函数参数?
我们具有从 QQuickItem
(qt quick(派生的qml ui对象,该对象是 QObject
和其他'辅助'对象,也用于从 QObject
base得出的QML中使用的QML。
// QObject pointer should work with QML objects
Q_INVOKABLE void receiveComponent(QObject* pObj);
请注意,那里还有QString
,QVariant
,QVariantList
,QVariantMap
和其他QT原语。用于参考。
相关文章:
- 错误-我无法在VS2019中打开新的Qt项目
- 将QT项目导入Visual Studio 2019会给我带来很多LNK2001错误
- 尝试在 QT 项目中调用 Java 代码时未找到类异常
- 无法在默认Qt项目中打开源文件"ui_QtGuiApplication.h"
- 在路径的独立Qt项目中包括外部库
- 为Qt项目树中的所有项目定义全局宏
- CMake用于C++/Qt项目中的外部库
- 如何将ICU库添加到ARM的Qt项目中
- 将libtensorflow_cc.so文件链接到QT项目
- 将网络添加到Qt项目
- 编译Qt项目,得到错误QQmlEngine:没有这样的文件或目录编译终止
- 是否可以在QT项目中使用Tensorflow C++ API?
- 在Qt C++项目中使用Go
- 编译Qt项目给出了对运算符delete(void*,unsigned int)的未定义引用
- 为Qt项目的每个模块添加一个包含
- 如何使用.UI文件在QT Creator中使用CMAKE制作GUI QT项目
- 在Qt项目中包括谷歌测试
- Qt项目与自定义共享库交叉编译Qt
- 如何从Qt C++项目运行Python函数
- 如何使用 qmake 将 pcl 库成功添加到 qt 项目中