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 can I concatenate absolute path with relative path?
Forum Updated to NodeBB v4.3 + New Features

How can I concatenate absolute path with relative path?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 3.0k 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.
  • M Offline
    M Offline
    Mery_lamb
    wrote on 5 Jan 2021, 10:57 last edited by
    #1

    Hi,

    Is there any function in QDir that allow us to concatenate 2 path (one is direct path and the other one is relative)

    For example:

    path 1 is "C:/home/user1/project/data"

    path 2 is : "../data2/file.txt"

    the result should be a String equal to "C:/home/user1/project/data2/file.txt"

    I tried: QString finalPath = QDir("C:/home/user1/project/data").filePath("../data2/file.txt");
    but it is not working .

    please help me

    J 1 Reply Last reply 5 Jan 2021, 11:04
    0
    • M Mery_lamb
      5 Jan 2021, 10:57

      Hi,

      Is there any function in QDir that allow us to concatenate 2 path (one is direct path and the other one is relative)

      For example:

      path 1 is "C:/home/user1/project/data"

      path 2 is : "../data2/file.txt"

      the result should be a String equal to "C:/home/user1/project/data2/file.txt"

      I tried: QString finalPath = QDir("C:/home/user1/project/data").filePath("../data2/file.txt");
      but it is not working .

      please help me

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 5 Jan 2021, 11:04 last edited by
      #2

      @Mery_lamb

      C:/home/user1/project/data/../data2/file.txt
      is same as 
      C:/home/user1/project/data2/file.txt
      So you can simply append one path at the end of the other one.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      M 1 Reply Last reply 5 Jan 2021, 11:15
      3
      • J jsulm
        5 Jan 2021, 11:04

        @Mery_lamb

        C:/home/user1/project/data/../data2/file.txt
        is same as 
        C:/home/user1/project/data2/file.txt
        So you can simply append one path at the end of the other one.
        M Offline
        M Offline
        Mery_lamb
        wrote on 5 Jan 2021, 11:15 last edited by
        #3

        @jsulm Thank you I can use the result directly to parse the file later but if I want to show the result I want this one "C:/home/user1/project/data2/file.txt".

        I thought there is a function like .join in python which allow us to concatenate 2 paths .

        Thank you so much for your feedback it really helps me

        J 1 Reply Last reply 5 Jan 2021, 11:31
        0
        • M Mery_lamb
          5 Jan 2021, 11:15

          @jsulm Thank you I can use the result directly to parse the file later but if I want to show the result I want this one "C:/home/user1/project/data2/file.txt".

          I thought there is a function like .join in python which allow us to concatenate 2 paths .

          Thank you so much for your feedback it really helps me

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 5 Jan 2021, 11:31 last edited by
          #4

          @Mery_lamb Try https://doc.qt.io/qt-5/qdir.html#cleanPath with joined path C:/home/user1/project/data/../data2/file.txt

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          3

          1/4

          5 Jan 2021, 10:57

          • Login

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