Results 1 to 3 of 3

Thread: QDesktopServices::openUrl() not opening files in set path

  1. #1
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default QDesktopServices::openUrl() not opening files in set path

    I created a app directory browser using QListView, to display my desktop items.
    The following is my "file-opening" function:

    Qt Code:
    1. void MainWindow::click2(const QModelIndex &var/*index*/)
    2. {
    3. QString o = var.data(0).toString();
    4.  
    5. qDebug() << o;
    6. qDebug() << QDesktopServices::openUrl(o);
    7. }
    To copy to clipboard, switch view to plain text mode 

    So with that and my index set as current directory, I can open any file.But if I change its index to any other directory thats not its current, it fails and qDebug says :
    qDebug() << QDesktopServices:penUrl(o); --> --> false

    I did some testing and passing this:

    Qt Code:
    1. QUrl dir = directory+"\\"+var.data(0).toString();
    2. qDebug() << QDesktopServices::openUrl(dir);
    To copy to clipboard, switch view to plain text mode 

    still gives me:
    qDebug() << QDesktopServices:penUrl(dir); --> --> false

    Any idea why?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QDesktopServices::openUrl() not opening files in set path

    try to use this function QUrl::fromLocalFile.
    so? you should modify you code like this
    Qt Code:
    1. QUrl dir = QUrl::fromLocalFile(directory+"\\"+var.data(0).toString());
    2. qDebug() << QDesktopServices::openUrl(dir);
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    been_1990 (4th May 2009)

  4. #3
    Join Date
    Oct 2008
    Posts
    306
    Thanks
    6
    Thanked 9 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QDesktopServices::openUrl() not opening files in set path

    It worked! Thanks. Can you explain why this worked and not the former?

Similar Threads

  1. visual studio project files - adding extra files
    By luf in forum Qt Programming
    Replies: 3
    Last Post: 13th June 2008, 21:05
  2. Replies: 2
    Last Post: 3rd April 2007, 19:47
  3. Replies: 5
    Last Post: 22nd September 2006, 08:04
  4. Which path should I use?
    By Dark_Tower in forum Newbie
    Replies: 3
    Last Post: 8th April 2006, 12:09
  5. [Win32/VC++ 8.0] Strange problems with qrc_*.cpp files
    By mloskot in forum Installation and Deployment
    Replies: 6
    Last Post: 6th March 2006, 10:28

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.