Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved] Directory path with space



  • 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.



  • 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 += "\\";
    }
    }
    @


  • Lifetime Qt Champion

    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 ?



  • 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.


  • Lifetime Qt Champion

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



  • 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


  • Lifetime Qt Champion

    You can also use QDir::fromNativeSeparators



  • I used but did not work!


Log in to reply