qml 动态创建的FileDialog程序异常问题

来源:互联网 发布:mysql 查询最近一周 编辑:程序博客网 时间:2024/05/16 09:44

现象:文件夹对话框打开后操作异常(有时候操作一次,有时候操作很多次),程序结束

代码:

AlterButton{            id:loadExisted;            m_iHangPosFlag: 1;            m_strBtnTips: "打开已有列表";            width: 35;            height: 30;            color: "transparent";            normalImage: "qrc:/res/open.png";            pressedImage: "qrc:/res/open.png";            onClicked: { ***               fileDia.createObject();            }        }Component{        id:fileDia        FileDialog {            nameFilters: [ "Xml files (*.xml)", "All files (*)" ]            id: fileDialog            title: "请选择要打开的文件"            onAccepted: {                GlobalVar.xmlPath = fileDialog.fileUrls[0];                XmlWriter.setXMLPath(GlobalVar.xmlPath);                GlobalVar.newXmlFlag = false;                GlobalVar.pageFlag = 0;            }            onRejected: {                GlobalVar.xmlPath = "";            }            Component.onCompleted: visible = true        }    }
原因:***动态创建对象未指定父对象:

改为:fileDia.createObject(parent);

后正常