Results 1 to 6 of 6

Thread: Opening pdf files from a Dir.

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Smile Opening pdf files from a Dir.

    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. MainWindowScreenShort.jpg.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Opening pdf files from a Dir.

    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,
    _

  3. #3
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Opening pdf files from a Dir.

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Opening pdf files from a Dir.

    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,
    _

  5. #5
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Opening pdf files from a Dir.

    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.
    Qt Code:
    1. void MainWindow::on_listView_Main_doubleClicked(const QModelIndex &index)
    2. {
    3. QString file_path = model->fileInfo(index).absoluteFilePath();
    4.  
    5. QUrl fPath;
    6. QDesktopServices::openUrl(fPath.fromLocalFile(file_path));
    7. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ayanda83; 8th October 2016 at 18:11.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,418
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Opening pdf files from a Dir.

    Ah, you meant opening in the file in an external program.

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

    Cheers,
    _

Similar Threads

  1. Opening files from a pinned Qt Application
    By newtoQ_s in forum General Programming
    Replies: 7
    Last Post: 24th November 2015, 07:56
  2. Replies: 2
    Last Post: 7th August 2013, 16:51
  3. opening PPT files in Qt
    By jay in forum Qt Programming
    Replies: 5
    Last Post: 14th May 2009, 12:20
  4. QDesktopServices::openUrl() not opening files in set path
    By been_1990 in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2009, 18:34
  5. Replies: 7
    Last Post: 20th December 2007, 09:56

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.