qt - Preserve non-ascii characters between std::string and QString -


Users in my program can either use a file name or QFileDialog on the command line . In the first case, I have a four * no encoding information, in the second I have QString .

Use to store the file name later (recent files), I should call it as QString . But to open the file with std :: ifstream , I need the std :: string .

Now the fun begins I can:

  filename = QString :: fromLocal8bit (argv [1]);  

Later, I can:

  std :: string fn = filename.toLocal8bit (). ConstData ();  

This works for most characters, but not all. For example, the word conversion will appear after this type of conversion, but in fact, there are different characters. Therefore, when I can have a RAITIVE.txt, and it will display the RiaTap, the file will not be found in the file. Most of the letters work, but no. (Note that when the file was selected in QFileDialog , it works properly. This does not happen when it is generated from the command line.)

Is there a better way to preserve the file name? Right now, I get it in any original encoding, and can enter the same encoding, without knowing it. At least I thought.

'and' is not an ASCII character, which is to say it has no 8-bit representation How OS is shown in argv [1] then OS is dependent but it is not appearing in just one char .

fromLocal8bit uses the same kind as toLocal8bit . And as you say if this is your std :: string "Раиса.txt" then this is not a problem.

According to the definition of your OS, std :: ifstream Although std :: ifstream will be used for each char Code> char and do not go through the translation of the OS I hope you are on Windows because you are seeing this problem. In that case, you should use the implementation of std :: wstring std :: fstream which is Microsoft specific:

You can enter a For more information, see here:

Edit:

A good cross-platform option for projects with access to them is specifically mentioned as mentioned.


Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -