Question

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.

Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top