qtsql: Query inserts malformed UTF-8 text to MySQL

390 views Asked by At

I want to connect to my MySQL database and insert some UTF8 strings. But when I do the insert query, some text like سسسسسسسسسسسسسسسس is inserted into my table.

This is my code:

s = QtCore.QString("insert into test4 values(''  , ' شسشس')");
self.onlineQuery.exec_(s);

What's wrong with my query?

Edit:

I solved the problem with this code:

QtCore.QTextCodec.setCodecForCStrings(QtCore.QTextCodec.codecForName("UTF-8"))
QtCore.QTextCodec.setCodecForLocale ( QtCore.QTextCodec.codecForName("UTF-8"))
1

There are 1 answers

0
Emil Vikström On BEST ANSWER

Make sure the connection charset is set to UTF-8. This is not always the default.