Problem description: In my program, I want to use the following code to change the prompt in the input field to “Please enter your password”. But the program error, unable to recognize Chinese characters.
Problem analysis: The encoding mode of the code file Login. CPP is not correct. Changing the encoding mode of the file login. CPP to UTF-8 can solve this problem. The method I used to modify the encoding method of the file was to open the CPP file with notepad software and select the encoding form of the file in the “Save as” window:

After saving the file as UTF-8, reload the file and compile the program. The error disappears and the Chinese character can be displayed normally.
QLineEdit *passwordEdit;
passwordEdit->setPlaceholderText("Enter your password please");
solution: use QString::fromLocal8Bit() method to transcode Chinese characters, the program can normally recognize Chinese character QString. Change the above code as follows:
QString str;
str=str.fromLocal8Bit("Enter your password please");
passwordEdit->setPlaceholderText(str);
another problem: program error “error C2001: newline in constant”
Problem analysis: The encoding mode of the code file Login. CPP is not correct. Changing the encoding mode of the file login. CPP to UTF-8 can solve this problem. The method I used to modify the encoding method of the file was to open the CPP file with notepad software and select the encoding form of the file in the “Save as” window:

After saving the file as UTF-8, reload the file and compile the program. The error disappears and the Chinese character can be displayed normally.
Read More:
- Solving the problem of Chinese garbled code in qtring
- Compiler error message: cs1056: unexpected character handling
- Java prompt unmappable character for encoding solution
- ASP.NET How to deal with “unexpected character” when writing code
- Run Python file for the first time with eclipse / pydev: “UTF-8 ‘codec can’t decode byte 0xc4 in position
- error: stray ‘\240’ in program
- Solution of Unicode decodeerror -‘utf-8 ‘codec can’t decode byte 0xc4 in position 0 – invalid continuation byte
- Python string prefix
- Error: the solution of “241” and “343” in program
- Perfectly solve the 1366 error of saving Chinese in MySQL
- Remove M Characters “Control M” or “^M” or “CTRL M” Characters in a UNIX file
- MySQL modify character set
- _ASSERTE((unsigned)(c + 1) <= 256);
- cvc-complex-type.2.3: Element ‘beans’ cannot have character [children]
- Texstudio prompts an error when compiling and viewing latex documents: package inputerror: Unicode character
- modelsim Error: (vlog-13067) Syntax error, unexpected non-printable character.
- Regular expressions filter special characters
- Typeerror: write() argument must be STR, not bytes and the method of writing binary file in Python 3
- Solution to the problem of Chinese garbled in gradle console in idea
- XML load error fix v0.1