Home > Back-end >  QTextCodec: : codecForName can't identify Chinese GBK code GB2312 GB18030
QTextCodec: : codecForName can't identify Chinese GBK code GB2312 GB18030

Time:09-24

Environment: Windows 7 VS2010, Qt (4.8.6)//to run the following code strange place
P1=QTextCodec QTextCodec * : : codecForName (" utf-8 ");
QTextCodec * p2=QTextCodec: : codecForName (" system ");
P3=QTextCodec QTextCodec * : : codecForName (" GB18030 ");//p3 get NULL
QTextCodec * p4=QTextCodec: : codecForName (" GBK ");//p4 get NULL
P5 QTextCodec *=QTextCodec: : codecForName (" gb2312 ");//p5 get NULL
P6 QTextCodec *=QTextCodec: : codecForLocale ();


QList Array=QTextCodec: : availableCodecs ();
for(int i=0; I{
QDebug () & lt; }

Checked the D: \ Qt \ 4.8.6 \ plugins \ codecs
Have qcncodecs4 DLL, qcncodecsd4. DLL and corresponding.lib file

Another person's computer and the environment, its p3, p4, p5 is not NULL

Day the search on the net, I found no effective method to help ah

CodePudding user response:

http://www.tc5u.com/mobile/129221.htm

In QT installation directory, a plugins \ codecs
Directory, there are several Asian literal encoding related DLL file, and Chinese code related files is:
Qcncodecs4. DLL (release version), qcncodecsd4. DLL version (debug),

Below the generated qt program directory, create a plugin directory, then create a codecs in the plugin directory under the directory,
Then put qcncodecs4. DLL or qcncodecsd4. DLL (you use this file if you need to debug) copy to codecs directory below,

Then add the following the red part in the main function of the code

QApplication a (arg c, argv);

QString sPath=a.a pplicationDirPath ();
SPath +=QString ("/plugins/");
A.a ddLibraryPath (sPath);

There's a place to note: be sure to put the files in directory under the name of codecs, below codecs cannot be changed to other names, and then specify load dynamic library catalog, can only be loaded codecs directory directory at the next higher level, which is the plugin directory,

QT program will automatically in the plugin directory codecs directory below loading qcncodecs4. DLL this library,


Then, the problem solved,

CodePudding user response:

The plugin directory under the project directory, level, with the CPP file path as follows a better
QString sPath=QString ("./plugins/");
A.a ddLibraryPath (sPath);
  • Related