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. browse into QUrl
Forum Updated to NodeBB v4.3 + New Features

browse into QUrl

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 903 Views 2 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.
  • D Offline
    D Offline
    dridk2
    wrote on last edited by
    #1

    Hi,

    I Wonder how to extract subpath from a QUrl.
    For instance, I have a path /A/B/C/D then I want only the path of the second upper directory: /A/B

    Is there an elegant way to do it without string manipulation?
    Something working like cd .. bash ommand?

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

      Hi and welcome
      If there is always at least 2 paths you could just split it to a list
      QString input = your QUrl;
      QStringList lines = input.split('/');
      then you can get the parts using lines list.

      Not super elegant. but better than hardcore string manipulation :)

      D 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi and welcome
        If there is always at least 2 paths you could just split it to a list
        QString input = your QUrl;
        QStringList lines = input.split('/');
        then you can get the parts using lines list.

        Not super elegant. but better than hardcore string manipulation :)

        D Offline
        D Offline
        dridk2
        wrote on last edited by
        #3

        @mrjj But it is not cross platform.. Windows use " \ " and linux " / " .
        So, I can use QDir::seperator ... Or split using a regular expression .

        Thanks for your reply

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Just a note.
          you can use c:/somepath/blabla in windows too :)
          (from within Qt)

          But yes, you are correct, using seperator is needed for external coming paths.

          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