Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-84572

Provide QUrl to Qt path conversion utils

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • P4: Low
    • None
    • None
    • Core: URL Handling
    • None

    Description

      In QTBUG-63076, it has been already suggested by iamsergio to add a QUrl parameterized constructor to QFile. While I understand the reasons given thiago why they don't want this constructor to be added to QFile, I agree with iamsergio that more dev support would be helpful here. Why not add some conversion helpers to Qt? Sth. along the lines of

      inline QUrl urlFromLocalPath(QString path)
      {
          auto scheme = QStringLiteral("file");
      
          if (!path.isEmpty() && path.at(0) == ':')
          {
              path.remove(0, 1);
              scheme = QStringLiteral("qrc");
          }
      
          QUrl url = QUrl::fromLocalFile(path);
          url.setScheme(scheme);
      
          return url;
      }
      
      inline QString localUrlToFilePath(QUrl url)
      {
          QString path =
              url.scheme() == QLatin1String("qrc") ? url.path() : url.toLocalFile();
      
          Q_ASSERT_X(url.scheme() == QLatin1String("qrc") || url.scheme() == QLatin1String("file"),
                     "localUrlToFilePath",
                     "url conversion to paths only makes sense for local file or qrc urls");
      
          if (url.scheme() == QLatin1String("qrc"))
          {
              path.prepend(':');
          }
      
          return path;
      }
      

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-84572
          # Subject Branch Project Status CR V

          Activity

            People

              cnn Qt Core & Network
              micu Michael Voigt
              Vladimir Minenko Vladimir Minenko
              Alex Blasche Alex Blasche
              Votes:
              4 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There is 1 open Gerrit change