Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. Common AppData folder error with special character
Qt 6.11 is out! See what's new in the release blog

Common AppData folder error with special character

Scheduled Pinned Locked Moved Solved Installation and Deployment
5 Posts 2 Posters 2.8k 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.
  • A Offline
    A Offline
    alecs26
    wrote on last edited by
    #1

    Hello,

    For my program (Qt MinGW 5.7 on Windows), I use a writable folder to store user parameters (to read and write).
    I use "QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);"

    It works on many computers with different Windows versions (I tried on 10 computers). However, with one computer, my program is not able to find the user's parameters. I investigated and found out that the username has a special character.
    The username is Andrée-Anne (a French name).
    The parameter location is "C:\Users\Andrée-Anne\AppData\Roamaing\MyProgram".

    However, the result of
    "qDebug() << QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);" is
    "C:\Users\AndreÚ-Anne\AppData\Roamaing\MyProgram".

    The character " é " is replaced by " Ú ". I guess this is why the program does not find the parameters.

    Any idea of what I could do ?? I know it's not a good idea to place special character anywhere but I must support my users who chose that...

    Thank you very much,

    Alex

    jsulmJ 1 Reply Last reply
    0
    • A alecs26

      Hello,

      For my program (Qt MinGW 5.7 on Windows), I use a writable folder to store user parameters (to read and write).
      I use "QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);"

      It works on many computers with different Windows versions (I tried on 10 computers). However, with one computer, my program is not able to find the user's parameters. I investigated and found out that the username has a special character.
      The username is Andrée-Anne (a French name).
      The parameter location is "C:\Users\Andrée-Anne\AppData\Roamaing\MyProgram".

      However, the result of
      "qDebug() << QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);" is
      "C:\Users\AndreÚ-Anne\AppData\Roamaing\MyProgram".

      The character " é " is replaced by " Ú ". I guess this is why the program does not find the parameters.

      Any idea of what I could do ?? I know it's not a good idea to place special character anywhere but I must support my users who chose that...

      Thank you very much,

      Alex

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @alecs26 Can you show the code where you use the path returned by QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);?
      The wrong output with qDebug could be an issue with console.

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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alecs26
        wrote on last edited by alecs26
        #3

        @jsulm thank you for your answer. Here is an example of write and read. They both work with every other computer but fail on this one.

        QString pathparam;
        pathparam = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/ParamBasic.txt";
        
        std::ofstream myfile;
        myfile.open(pathparam.toStdString(), std::ofstream::out | std::ofstream::trunc);
        myfile << p1 ;
        myfile.close();
        

        and

        QString appparamfolderloc=QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/ParamBasic.txt";
        std::ifstream myfile(appparamfolderloc.toStdString());
            if (myfile.is_open())
            {
                while (getline(myfile, line))
                {
                    std::stringstream os(line);
                    os >> line2;
                }
            }
        myfile.close();
        

        Thanks !

        Alex

        jsulmJ 1 Reply Last reply
        0
        • A alecs26

          @jsulm thank you for your answer. Here is an example of write and read. They both work with every other computer but fail on this one.

          QString pathparam;
          pathparam = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/ParamBasic.txt";
          
          std::ofstream myfile;
          myfile.open(pathparam.toStdString(), std::ofstream::out | std::ofstream::trunc);
          myfile << p1 ;
          myfile.close();
          

          and

          QString appparamfolderloc=QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/ParamBasic.txt";
          std::ifstream myfile(appparamfolderloc.toStdString());
              if (myfile.is_open())
              {
                  while (getline(myfile, line))
                  {
                      std::stringstream os(line);
                      os >> line2;
                  }
              }
          myfile.close();
          

          Thanks !

          Alex

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @alecs26 Why don't you use QFile?
          The problem could be pathparam.toStdString().
          Try with QFile without calling pathparam.toStdString() as QFile accepts QString.

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

          1 Reply Last reply
          2
          • A Offline
            A Offline
            alecs26
            wrote on last edited by
            #5

            @jsulm Thank you so so so much !! It works !
            I did not use QFile because I recycled a VStudio code for processing text file and I was too lazy to convert it in QFile. I should have done it !

            Thanks again,

            Alex

            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