My attack on PyQt4 programming (with resources)
juli 3, 2009
I have been catching up on my python programming the last week. Even more so, I have been catching up on GUI programming with PyQt4. I haven’t programmed anything graphical since maybe early 2005, so beginning again was a bit of a chock. I have spent two days on a ”New beginning” with python and Qt, and it is actually starting to shape up.
My first app was a small chatt client for an even smaller chat server I programmed earlier this week (it just delivers messages between the connected peers, and it has buggy-as-hell groupchat capabilities). Needles to say I encountered many small problems – and of course a couple of huge ones as well.
Out of nowhere I started getting some really weird ”XRender Bad glyphset 152″ output in my app, and All I was doing was appending UTF-8 text to a QTextEdit. Seems I overlooked a small thing:
You cannot access and change Widgets created in another thread. From what I remember from using GTK, and previous versions of Qt this has always been. (Qt was a bit better back then, though). You just cannot in any way modify the GUI from another thread.
Anyways: the way to get around this is of course to use signals and slots.
Another small promlem I kept getting was that a QTextEdit always got me ascii text when I converted the QString to a pyhton string. I fiddled around with some various str.encode() and str.decode() before I found the QString.toUtf8(). That did the job.
I thought I would make this a small pyqt series with a bit of information about the problems I have had. People seemed to appreciate my lite info-thingie about how to get knemo running in KDE4.1, and perhaps someone might find this page through google. While googling for some pyqt stuff.
The resources I have found valuable are:
The Qt C++ reference – requires some aptness in understanding c++
ZetCode – Really not that great as a reference, but it helps the beginner in grokking the basics
Rempt’s book – Quite outdated, but still a great read. (can be downloaded with HTTRack)
Infopage on pyqt4 – not very explaining, but a good read.
EDIT: also found the Qt reference convertet to python:
http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/classes.html
And now, a screenshot of my editor, just to impress my brother:
