0

我刚刚开始在 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++ 代码中做同样的过程吗?

4

1 回答 1

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

于 2014-08-14T19:54:55.673 回答