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. How to get the source QString instance from a QUrl instance which is invalid?
Qt 6.11 is out! See what's new in the release blog

How to get the source QString instance from a QUrl instance which is invalid?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.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.
  • Z Offline
    Z Offline
    ZiJia
    wrote on last edited by
    #1

    I have constructed a QUrl instance like below.

    0_1498033730665_H5r2vVVXf#rehG5kWOycMg==.png

    Here is a output from PyQt4, actually i use Qt5, but it isn't installed on this machine, so it's just a sample code to demonstrate my problem.

    In Qt5, i want to get the source string "test.pro://account=" from the QUrl instance, how can i achieve it?

    What i have done?

    The QUrl class have a private class which is named QUrlPrivate which contains a struct named Error. The Error structure contains QString source which is actually what i want. But i don't know how to access it usinig public API from QUrl.

    Thanks for helping.

    m.sueM 1 Reply Last reply
    0
    • Z ZiJia

      I have constructed a QUrl instance like below.

      0_1498033730665_H5r2vVVXf#rehG5kWOycMg==.png

      Here is a output from PyQt4, actually i use Qt5, but it isn't installed on this machine, so it's just a sample code to demonstrate my problem.

      In Qt5, i want to get the source string "test.pro://account=" from the QUrl instance, how can i achieve it?

      What i have done?

      The QUrl class have a private class which is named QUrlPrivate which contains a struct named Error. The Error structure contains QString source which is actually what i want. But i don't know how to access it usinig public API from QUrl.

      Thanks for helping.

      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

      @ZiJia

      Hi,

      do you have the same problem with a more regular and existing Url like e.g. "http://forum.qt.io"?

      -Michael.

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        ZiJia
        wrote on last edited by
        #3

        @m-sue

        No.

        m.sueM 1 Reply Last reply
        0
        • Z ZiJia

          @m-sue

          No.

          m.sueM Offline
          m.sueM Offline
          m.sue
          wrote on last edited by
          #4

          Hi @ZiJia

          According to the docs: "QUrl checks for conformance with the URL specification". So I would guess that QUrl does not recognise "test.pro://" as valid url protocol and it stops where it finds the first error.

          -Michael.

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            ZiJia
            wrote on last edited by
            #5

            @m-sue You are right. QUrl parser considers it as an error. But what i want to do is to get the source string when it goes wrong.

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

              Hi,

              Since you have your variable named source, why not re-use it if something fails ?

              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
              1

              • Login

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