QT QML 界面设计教程19—— 文件对话框

1、MyFileDialog.qml

import QtQuick 2.12
import QtQuick.Controls 2.12
import QtQuick.Dialogs 1.3
FileDialog {
        id: myfileDialog
        signal mySignal(string info)
        property string filaname: myfileDialog.fileUrl
        title: qsTr("Please choose a file")
        nameFilters: ["txt Files (*.txt)","All Files (*)"]
        selectMultiple: false
        //selectMultiple: true

        // 设置默认打开路径为当前用户的桌面
        onAccepted: {
            console.log("You chose: " + myfileDialog.fileUrls)
            console.log("You chose1: " + myfileDialog.fileUrl)
            console.log("You chose3: " + myfileDialog.folder)
            filaname = myfileDialog.fileUrl
            filaname = filaname.toString().substring(8,filaname.length)
            console.log("You chose4 " + filaname)
            mySignal(filaname)
        }
        onRejected: {
            console.log("Canceled")
        }

        Component.onCompleted: {
            // 在这里设置默认路径
            folder = StandardPaths.writableLocation(StandardPaths.DesktopLocation)
        }
 }


2、调用

   CNCFileDialog{
        id: fileDlg
        property string inputValue: ""
        onMySignal: {
            fileDlg.inputValue = fileDlg.filaname
            //自定义函数调用,传值“fileDlg.inputValue”       
            。。。。。
        }

    }       
     Button {
                id: btChange
                x: 10
                y: 30
                width: 164
                height: 30
                inputValue:"打开"

                onClicked:{
                    fileDlg.open()
                    
                }
            }

3、异常处理:module "QtQuick.Dialogs" is not installed

将qml目录下的Qt和QtQuick目录复制到qt工程的运行目录

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

notfindjob

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值