QTableWidget insert strings from mysql from different unicode

I was using the qt sql system for loading a mySQL database from wordpress and putting it in a qtablewidget. It was working fine, but since I know in the future the gui will change, I am trying to remove dependency on qt for anything except displaying the information. So I switched to pythons mysqldb library. Now when I try to populate by:

    for data in data:
        for i in range(len(data)):
            self.sqlTableWidget.setItem(index,i,QtGui.QTableWidgetItem(str(data[i])))
        index = index+1

However, this makes the foreign language in posts (korean) turn into ‘????’. I then tried to use Qstring, however, it says that i am giving it datetime.datetime as an argument. I see that there is a date and time, however when I use str(data[i]) it just displays as a string of time.

Read More

What is the proper way of inserting this data while maintaining the language?

Edit:

I think it may have to do with the encoding, but im not sure how I can do. I added charset='utf8' to my connect() and now it gives the error “UnicodeEncodeError: ‘charmap’ codec can’t encode characters in position 0-5: character maps to (undefined).

I was able to find some info on the MySQL website, and found SHOW VARIABLES. When I used it I got this information, but I dont know how to use it to correct the problem.enter image description here

Related posts

Leave a Reply