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(QUrl()) saying file doesn't exist, when it does

[SOLVED]QDesktopServices::openUrl(QUrl()) saying file doesn't exist, when it does

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 6.8k Views
  • 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.
  • T Offline
    T Offline
    Tory Gaurnier
    wrote on last edited by
    #1

    I'm trying to open a file with QDesktopServices::openUrl(QUrl()), I have a QString url with value "/home/username/my file.pdf", and when I run QDesktopServices::openUrl(QUrl(url)) I get the following error:
    gvfs-open: /home/username/mypercent20file.pdf: error opening location: Error when getting information for file '/home/username/mypercent20file.pdf': No such file or directory

    Now it's obviously encoding the string correctly, putting the percent20s in for spaces and whatnot, but it's saying that the file doesn't exist??? Is it maybe looking relative to my home directory or working directory or something? If it's looking relative to root directory (as it should with that url), then it should be able to find the file.

    1 Reply Last reply
    0
    • 8 Offline
      8 Offline
      8majkel8
      wrote on last edited by
      #2

      you have to convert path (/some/file/here) to url form (file:///some/path/here)

      @
      QString path = "/some/path/here";
      QUrl pathUrl = QUrl::fromLocalFile(path);
      QDesktopServices::openUrl(pathUrl);
      @

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Tory Gaurnier
        wrote on last edited by
        #3

        Ahhhh, see, I tried QUrl::toLocalFile, thinking it would convert to a local file url, it seems I got them mixed up. It's strange because the first thing I tried was
        @QString url = "file:///home/username/my file.pdf"@

        However when feeding that to QUrl it was replacing the file extention with a space o_O
        So it would convert to "file:///home/username/mypercent20file "

        Anyhow, thanks for the help, I really appreciate it! I've had nothing but good luck getting help on these forums _^__^

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ctsiitmail
          wrote on last edited by
          #4

          Please help me.
          How can i convert QT 4.8 code - To - QT 5.2 code that i indeed.

          --------------------------------------------Thax--------------------------------------------------

          #ifndef STDLOCATION_H
          #define STDLOCATION_H

          #include <QDir>
          #include <QFileInfo>
          #include <QDesktopServices>
          #include <QDateTime>
          #include "settings.h"

          #define SL_TRANSFERHISTORY "transfers.lst"
          #define SL_FILESTORAGEDIR "Received Files"
          #define SL_CACHEDIR "cache"
          #define SL_RESOURCE "lmc.rcc"
          #define SL_LANGDIR "lang"
          #define SL_THEMEDIR "themes"
          #define SL_GROUPFILE "group.cfg"
          #define SL_AVATARFILE "avt_local.png"
          #define SL_LOGDIR "logs"
          #define SL_TEMPCONFIG "lmctmpconf.ini"

          class StdLocation {
          public:

          static QString transferHistory(void) {
          return QDir::toNativeSeparators(QDesktopServices::storageLocation(
          QDesktopServices::DataLocation) + "/"SL_TRANSFERHISTORY);
          }

          static QString fileStorageDir(void) {
          lmcSettings settings;

          QString path = QDir::toNativeSeparators(QDesktopServices::storageLocation(
          QDesktopServices::DocumentsLocation) + "/"SL_FILESTORAGEDIR);
          path = settings.value(IDS_FILESTORAGEPATH, path).toString();
          return path;
          }

          static QString cacheDir(void) {
          return QDir::toNativeSeparators(QDesktopServices::storageLocation(
          QDesktopServices::DataLocation) + "/"SL_CACHEDIR);
          }

          static QString libDir(void) {
          return QDir::toNativeSeparators(QDir::currentPath());
          }

          static QString resourceFile(void) {
          return QDir::toNativeSeparators(QDir::current().absoluteFilePath(SL_RESOURCE));
          }

          static QString resLangDir(void) {
          return ":/"SL_LANGDIR;
          }

          static QString sysLangDir(void) {
          return QDir::toNativeSeparators(QDir::currentPath() + "/"SL_LANGDIR);
          }

          static QString userLangDir(void) {
          return QDir::toNativeSeparators(QDesktopServices::storageLocation(
          QDesktopServices::DataLocation) + "/"SL_LANGDIR);
          }

          static QString resThemeDir(void) {
          return ":/"SL_THEMEDIR;
          }

          static QString sysThemeDir(void) {
          return QDir::toNativeSeparators(QDir::currentPath() + "/"SL_THEMEDIR);
          }

          static QString userThemeDir(void) {
          return QDir::toNativeSeparators(QDesktopServices::storageLocation(
          QDesktopServices::DataLocation) + "/"SL_THEMEDIR);
          }

          static QString groupFile(void) {
          return QDir::toNativeSeparators(QDesktopServices::storageLocation(
          QDesktopServices::DataLocation) + "/"SL_GROUPFILE);
          }

          static QString avatarFile(void) {
          return QDir::toNativeSeparators(QDesktopServices::storageLocation(
          QDesktopServices::DataLocation) + "/"SL_AVATARFILE);
          }

          static QString logDir(void) {
          return QDir::toNativeSeparators(QDesktopServices::storageLocation(
          QDesktopServices::DataLocation) + "/"SL_LOGDIR);
          }

          static QString freeLogFile(void) {
          QString fileName = "lmc_" +
          QString::number(QDateTime::currentDateTimeUtc().toMSecsSinceEpoch()) + ".log";
          return QDir::toNativeSeparators(logDir() + "/" + fileName);
          }

          static QString tempConfigFile(void) {
          return QDir::toNativeSeparators(QDesktopServices::storageLocation(
          QDesktopServices::TempLocation) + "/"SL_TEMPCONFIG);
          }
          };

          #endif // STDLOCATION_H

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            ctsiitmail

            Please stop asking the same questions on every thread related to QDesktopServices, open your own thread asking for help.

            First thing you should do is follow the porting guide from Qt 5's documentation.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ctsiitmail
              wrote on last edited by
              #6

              Please help me solve in QT 5.2
              Anyone help me to convert, Converter or translate software for qt 4.8 to qt 5.2

              facing warning:

              FileView has not been dexlared

              void updateProgress(FileView* view, qint64 currentPos);

              void setButtonState(FileView::TransferState state);

              Ui::TransferWindow ui;

              QList<FileView> pendingSendList;

              ui.setupUi(this);

              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