0

I've just started to deploy my first application for Ubuntu using QtCreator 3.1.1 based on Qt5.2.1 on Ubuntu 14.10.. I need to open some video files, so I'm going to put a Button to choose file obviously. Also I know I can use this function to open files:

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
}

Here's my question: How can I connect them to each other? I want the FielDialog to be opened when I click on the button. And is that the only way to do this? I mean couldn't I do the same process in C++ code?

sheshkovsky
  • 1,302
  • 3
  • 18
  • 41

1 Answers1

1

Of course you can do in C++. There's a Qt class called QFileDialog: http://qt-project.org/doc/qt-5/QFileDialog.html You can simply connect a button clicked signal to a slot that creates a QFileDialog, you can use some of the static functions like in the example:

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

and here how to use the QPushButton: http://qt-project.org/wiki/How_to_Use_QPushButton

dfranca
  • 5,156
  • 2
  • 32
  • 60
  • QPushButton works fine, but I'd rather to do it in qml only. Do you know how can I do that? – sheshkovsky Aug 14 '14 at 21:43
  • Sure, you can use a MouseArea inside a Rectangle for example: http://qt-project.org/doc/qt-4.8/qml-mousearea.html And then call your FileDialog from there: http://qt-project.org/doc/qt-5/qml-qtquick-dialogs-filedialog.html – dfranca Aug 14 '14 at 21:50