Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]QDesktopServices::openUrl() fails to open a file with spaces
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]QDesktopServices::openUrl() fails to open a file with spaces

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 11.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    adnan
    wrote on last edited by
    #1

    If i try opening a file:
    @QString str="/home/ab/My Video.avi";
    QDesktopServices::openUrl(str);
    @

    It flags an error like : /home/ab/Mypercent20Video.avi does not exist. It seems QDesktopServices::openUrl() automatically encodes the url.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      @
      QString str="/home/ab/My Video.avi";
      QDesktopServices::openUrl(QUrl::fromLocalFile(str));
      @

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      1
      • A Offline
        A Offline
        AcerExtensa
        wrote on last edited by
        #3

        If you pass QString instead of QUrl this will be automatically converted to:
        @
        QString str="/home/ab/My Video.avi";
        QDesktopServices::openUrl(QUrl(str));
        @

        and Qurl::QUrl(const QString &) constructor says:

        bq. Constructs a URL by parsing url. url is assumed to be in human readable representation, with no percent encoding. QUrl will automatically percent encode all characters that are not allowed in a URL. The default parsing mode is TolerantMode.

        Always use QUrl with right constructor or static function...

        And please add "[SOLVED]" prefix left to the topic subject.

        God is Real unless explicitly declared as Integer.

        1 Reply Last reply
        3
        • A Offline
          A Offline
          adnan
          wrote on last edited by
          #4

          Thanks a lot for your reply!

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved