PDA

View Full Version : Opening pdf files from a Dir.



ayanda83
8th October 2016, 14:32
Hi guys, I am using QFileSystemModel to pull files (i.e. pdf files) from a diretory and I am displaying them in a QListView. My problem now is getting the files to open when you double click on them. By "open" I mean when you double click on a file, it must pop-up and open. The attached picture shows how the files are displayed in the view. I know the solution to this is probably one line of code but I am clueless right now. I've already created a "double clicked" slot on the view indices but I just don't know what to add there:) Lastly the model is not displaying the file icons but this is not priority right now. 12148.

anda_skoa
8th October 2016, 15:04
You need to be a bit more precise what you are actually asking for.

Does your slot not get called?
Or do you have problem with code in your slot?

If the latter then you forgot to post the code of the slot.

Cheers,
_

ayanda83
8th October 2016, 15:14
My problem is getting the files to open when I double click on them, at the moment, that is not happening. As you can see on the attachment above, the files are already displayed in the view but when I try to open any of those files by double clicking on them, nothing happens. I know this needs to be handled in a double-clicked index slot for the view but I just don't know how its done. Hope this is clear.

anda_skoa
8th October 2016, 17:30
Files don't magically open just because you've connected an empty slot to a signal.
The signal/slot connection only triggeres execution of the code in that slot, nothing more.

So if the connection is OK and the slot is invoked, then the problem must be the code in that slot.
Which you have not posted yet.

Cheers,
_

ayanda83
8th October 2016, 19:11
I understand how signals and slots work. I just needed somebody to point me in the right direction as to how to get the file to open. I have not posted my code for the slot because that is exactly my problem, "THE CODE THAT MUST GO INTO THE SLOT". You don't have to write the code for me, you can just tell me which Qt objects to look at.

Added after 1 22 minutes:

For anybody who might have a similar problem in the future, I resolved this issue with little help from somebody. Please see the code below.

void MainWindow::on_listView_Main_doubleClicked(const QModelIndex &index)
{
QString file_path = model->fileInfo(index).absoluteFilePath();

QUrl fPath;
QDesktopServices::openUrl(fPath.fromLocalFile(file _path));
}

anda_skoa
8th October 2016, 20:56
Ah, you meant opening in the file in an external program.

You can remove the "fPath" variable, QUrl::fromLocalFile() is a static method.

Cheers,
_