Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt standard dialogs example: Open file

I'm beginning to learn Qt for use in one of my projects, and what I need to do is create a GUI that allows the user to open a file. I was looking through the examples and I found one of them that has exactly what I need; the problem is that it's also got a whole lot of other stuff, to the point where I have no idea what I'm looking at or what I'm looking for.

Basically, my question is this:

How do I make what you can see below in the image, where after clicking on the button and selecting the relevant file, it shows and stores the file path in the box to the right? enter image description here

I have already figured out how to make the button open the file dialog, my only problem is getting it to store and display the filepath.

like image 840
JM92 Avatar asked Jan 17 '13 04:01

JM92


1 Answers

Solved it with this:

void OpenXMLFile::on_File1Button_clicked()
{
    file1Name = QFileDialog::getOpenFileName(this,
         tr("Open XML File 1"), "/home", tr("XML Files (*.xml)"));
    ui->File1Path->setText(file1Name);

}

void OpenXMLFile::on_File2Button_clicked()
{
    file2Name = QFileDialog::getOpenFileName(this,
         tr("Open XML File 2"), "/home", tr("XML Files (*.xml)"));
    ui->File2Path->setText(file2Name);

}

Where this is my GUI:

enter image description here

(The boxes next to the buttons are Line Edits if anyone was wondering)

like image 95
JM92 Avatar answered Oct 01 '22 04:10

JM92