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. QUrl::setPath deletes Url
QtWS25 Last Chance

QUrl::setPath deletes Url

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.4k 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.
  • M Offline
    M Offline
    Maptuzu
    wrote on last edited by
    #1

    Hi,

    following example:

    @
    QUrl example1("http://www.example.com");
    example1.setPath("test.html");
    qDebug() << "example1:" << example1;

    QUrl example2("http://www.example.com");
    example2.setPath("/test.html");
    qDebug() << "example2:" << example2;
    @

    Output:
    @
    example1: QUrl( "" )
    example2: QUrl( "http://www.example.com/test.html" )
    @

    Can somebody explain to me, why url is deleted in the first example? Is there a reason why the slash is required? Sorry for my lack of knowledge.

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

      Hi,

      AFAIK, "test.html" is an invalid path. You can check the definition of what a path is in the documentation of setPath

      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
      • M Offline
        M Offline
        Maptuzu
        wrote on last edited by
        #3

        Yes, but does not explain why the slash is required.

        @
        QUrl example1("http://www.example.com");
        example1.setPath("pub/something");
        qDebug() << "example1:" << example1;

        QUrl example2("http://www.example.com");
        example2.setPath("/pub/something");
        qDebug() << "example2:" << example2;@

        @
        example1: QUrl( "" )
        example2: QUrl( "http://www.example.com/pub/something" )
        @

        P.S. in PySide the first slash is not necessary

        1 Reply Last reply
        0
        • M Offline
          M Offline
          Maptuzu
          wrote on last edited by
          #4

          Hmm, i've testet the code with Qt 4.8.6 and it works. Apparently, the behavior changed in Qt5.

          @
          QUrl example1("http://www.example.com");
          example1.setPath("pub/something");
          qDebug() << "example1:" << example1;

          QUrl example2("http://www.example.com");
          example2.setPath("/pub/something");
          qDebug() << "example2:" << example2;

          QUrl example3("http://www.example.com/");
          example3.setPath("////pub/something");
          qDebug() << "example3:" << example3;
          @

          Qt4.8.6 output;
          @
          example1: QUrl( "http://www.example.com/pub/something" )
          example2: QUrl( "http://www.example.com/pub/something" )
          example3: QUrl( "http://www.example.com////pub/something" )
          @

          Qt5.3.2 output:
          @
          example1: QUrl( "" )
          example2: QUrl( "http://www.example.com/pub/something" )
          example3: QUrl( "http://www.example.com/pub/something" )
          @

          Bug or Feature?

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

            Based on the current QUrl test, it's a feature, no slash means a relative path so your QUrl becomes invalid since you have an authority present before.

            Anyway, a check for that is on it's way

            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

            • Login

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