27 May

“Qtutils” is a useful pack

I come up with an problem: http://stackoverflow.com/questions/30180046/statusbar-doesnt-show-message-immediately-and-sometimes-crash

I created an interface in pyqt4 designer, there is only a button and a status bar. I want to show a message in the status bar when I click the button. For some reason I have to put this action in a new thread.

But when I click the button, nothing happened. The message didn’t appear until I drag the edge of the window. Sometimes the click action even cause the program to crash

as three_pineapples answered :”The crash happens because you are interacting with the Qt GUI from a secondary thread. You are only allowed to interact with the GUI from the main thread”.

He provided a very useful pack “qtutils”.

I define my interaction action as a new fuction, say shili(self). When I want to interact with GUI from a secondary thread, I simply write :

inmain(self.shili)

10 May

Chinese character coding problem in pyqt4

I want to save a file with a Chinese name in pyqt.

It reports: IOError: [Errno 22] invalid mode ('w') or filename: PyQt4.QtCore.QString(u'D:/Users/zhout_000/Desktop/\u672a\u547d\u540d.dxf')

Reason: the type of the filename read from the file dialog is infact “QString”, not”string”

Solve: convert QString to unicode: fileName=unicode(QtCore.QString(fileName))