如果想使用其他的qml文件直接创建对象,必须先这样导入其qml文件并as成别名,才可以创建对象并使用它。
一、导入qml文件,例如:
import "CameraConfig.qml" as CameraConfig
import "CameraDevelopView.qml" as CameraDevelopView
import "CameraDataView.qml" as CameraDataView
二、使用别名创建对象
CameraConfig {id: dlgCameraConfig //width和height是Dialog自身的属性,可直接调用,无需单独设计属性}CameraDataView {id: dlgCameraData}CameraDevelopView {id: idCamDevelop}
三、使用创建的对象
Menu {// 右键菜单id: contextMenuCameraMenuItem {text: "配置"onTriggered: {dlgCameraConfig.camid=viewMainid.currentcam;dlgCameraConfig.width=389dlgCameraConfig.height=401dlgCameraConfig.visible=true;dlgCameraConfig.updateData();dlgCameraConfig.open();}}MenuItem {text: "实时状态"onTriggered: {dlgCameraData.defaultindex=0dlgCameraData.width=664dlgCameraData.height=403dlgCameraData.defaultcamid=viewMainid.currentcamdlgCameraData.updateData4Status()dlgCameraData.open()}}MenuItem {text: "开发者界面"onTriggered: {idCamDevelop.camid=viewMainid.currentcamidCamDevelop.width=711idCamDevelop.height=487idCamDevelop.updateData()idCamDevelop.open()}}}
秋风写于淄博,业务交流与技术咨询:Q375172665