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. [Solved] Directory path with space
Forum Update on Monday, May 27th 2025

[Solved] Directory path with space

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 2.2k 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
    MohammadReza
    wrote on last edited by
    #1

    Hello friends.

    Maybe you think this question is solved more and more before, but I have another problem.
    For example the directory path is "C:\Program Files (x86)\sth".
    I don`t set it directly! I get it from registry. So, the directory path maybe different in another systems.
    How can I change the directory path to a valid one dynamically?

    Thanks a lot.
    Ya Ali.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MohammadReza
      wrote on last edited by
      #2

      Searching a lot and finding nothing major!

      But I wrote my own codes.
      @
      QList<QString> lst = installedPath.split("\");
      for(int i=0;i<lst.size(); i++)
      {
      if(lst.at(i).indexOf(" ") != -1)
      {
      validLocation += """;
      validLocation += lst.at(i);
      validLocation += """;
      validLocation += "\\";
      }
      else
      {
      validLocation += lst.at(i);
      if(i != lst.size()-1)
      validLocation += "\\";
      }
      }
      @

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

        Hi,

        There's something not really clear there, what do you mean by set it directly ? How do you retrieve that path in the first place ?

        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
          MohammadReza
          wrote on last edited by
          #4

          Hi dear SGaist,
          Thanks for your response.

          I mean define a QString and give "C:\Program Files (x86)\sth” directly to it:
          QSrting location = "C:\Program Files (x86)\sth”.
          My project is not like the above because I set the value of location from windows registry.

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

            How are you accessing the registry and what is the exact string you are getting ?

            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
              MohammadReza
              wrote on last edited by
              #6

              Here is the code:

              @
              QSettings settings("HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Wireshark", QSettings::NativeFormat);
              QString installedPath = settings.value("InstallLocation").toString();
              @

              The result is:
              C:\Program Files (x86)\Wireshark

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

                You can also use QDir::fromNativeSeparators

                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
                  MohammadReza
                  wrote on last edited by
                  #8

                  I used but did not work!

                  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