【问题标题】:How to connect a Button to FileDialog function in ubuntu sdk?如何在 ubuntu sdk 中将按钮连接到 FileDialog 函数?
【发布时间】:2014-08-14 19:06:59
【问题描述】:

我刚刚开始在 Ubuntu 14.10 上使用基于 Qt5.2.1 的 QtCreator 3.1.1 为 Ubuntu 部署我的第一个应用程序。我需要打开一些视频文件,所以我要放一个按钮来选择文件明显地。我也知道我可以使用此功能打开文件:

FileDialog {
    id: fileDialog
    title: "Please choose a file"
    onAccepted: {
        console.log("You chose: " + fileDialog.fileUrls)
        Qt.quit()
    }
    onRejected: {
        console.log("Canceled")
        Qt.quit()
    }
    Component.onCompleted: visible = true
}

这是我的问题:如何将它们相互连接?我希望在单击按钮时打开 FielDialog。这是唯一的方法吗?我的意思是我不能在 C++ 代码中做同样的过程吗?

【问题讨论】:

    标签: c++ qt ubuntu sdk qt5.2


    【解决方案1】:

    当然你可以用 C++ 做。 有一个名为 QFileDialog 的 Qt 类:http://qt-project.org/doc/qt-5/QFileDialog.html 您可以简单地将按钮单击信号连接到创建 QFileDialog 的插槽,您可以使用示例中的一些静态函数:

    fileName = QFileDialog::getOpenFileName(this,
        tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)"));
    

    以及如何使用 QPushButton:http://qt-project.org/wiki/How_to_Use_QPushButton

    【讨论】:

    猜你喜欢
    • 2021-10-30
    • 2021-10-01
    • 2016-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-01
    • 2023-03-30
    • 2016-02-08
    相关资源
    最近更新 更多