Montag, 26. August 2013

Using PyQt 5 with Spyder. Some crashes and a new idea.

So after doing the stuff I posted earlier, I went on to test a simple QtQuick app.
A simple red rectangle worked okay, but everything seemed to be very unstable. I got many crashes and freezes. Something was really fucked up. After experimenting on that setup for almost a full day, I uninstalled PyQt 5 with nmake uninstall and PyQt 4 with its uninstaller. I installed the binary package of PyQt 5 and tested my qml file.

It just worked fine. No crashes, no instabilities, no nothing.

It appears that my custom built was somehow corrupted, probably from the beginning or that there are some things to do in addition. I copied the PyQt 5 folder out of the site-packages folder of python, uninstalled it, reinstalled PyQt 4 and then copied PyQt 5 back to site-packages. Updated the module name list and BANG, it works. Don't now why this didn't occur to me earlier... 

PyQt 5, Spyder and the input hook.

As mentioned in the last post, the input hook of Spyder is actually necessary to interactively edit your application while running. So how to make Spyder install its hook to PyQt 5 instead of its own PyQt 4?
The solution is a bit hacky but quite simple: Go to your Python folder, like
 C:\Python33\Lib\site-packages\spyderlib\widgets\externalshell
there is file sitecustomize.py waiting for you. For safety make copy of that file as we are going to change it a little bit.
Now open it and find the lines (should be 247 to 249):
    if os.environ.get("INSTALL_QT_INPUTHOOK", "").lower() == "true":
        if os.environ["QT_API"] == 'pyqt':
            from PyQt4 import QtCore
And change the last  from
from PyQt4 import QtCore
to
from PyQt5 import QtCore
Now Spyder imports the QtCore module from PyQt 5 instead of PyQt 4. The hook is beeing installed on the first loading of QtCore, so when Sypder launches its consoles now, everything is fine.

Happy playing!


Using PyQt 5 with Spyder.

I have a toy project where I want to go the whole scripted/interpreted way with Qt. For that I use this toolchain: Qt 5.1 with QtQuick 2.0, PyQt 5 and Python 3.3. Lately my Python-Editor of choice, Spyder, does support Python 3.3, but it is based on PyQt 4 and a release of Qt 4. That does not fit my bill, as I need some new 5.0 stuff from the QMultimedia module. (If you need just Qt 4 functionality, that toolchain works like a charm and you can stop reading.)

Just downloading a binary release of PyQt 5 and installing it, fails as it detects the PyQt 4, which needs to be uninstalled first, but doing this kills Spyder. Bummer.
Downloading the source and building it (which is actually very straightforward, just follow the instructions in the readme - don't forget to do (n)make install and update the Python module name list (in Spyder)), does the trick. Now both PyQt releases are available.
But importing QtCore from PyQt 5 causes a runtime crash:
RuntimeError: the PyQt4.QtCore and PyQt5.QtCore modules both wrap the QObject class
Obviously PyQt 4 is imported, too. A quick
import sys
sys.modules.keys()​​​
confirms that. The reason for that is that Spyder installs a special input hook, replacing the input hook of PyQt, which is said to cause problems with Spyder. Fortunately you can disable this hook under Tools > Preferences > Console > External modules. After a restart of the current console, you can now import QtCore and you can start developing your stuff.
There is a slight annoying thing regarding the hook though: you now can not interactively work with your application in the console. The solution for that comes in the next post.

Update: read my follow up post for a simpler and better solution.

Montag, 14. Januar 2013

Wie stellt man unter Windows fest ob ein Programm als Release- oder Debug-Build kompiliert wurde?

Der Dependency Walker gibt die Antwort. Bei einem Release-Build wird die MSVCRT-Bibliothek geladen und bei einem Debug-Build die MSVCRTD-Bibliothek.

Dienstag, 30. Oktober 2012

Git Extensions kann Git Hooks.

Es scheint so zu sein als würde Git Extensions seit einiger Zeit Git Hooks verstehen. Was zur Folge hat, dass man mit Git Extensions auch für Qt Gerrit Commits erzeugen kann.
(Meine bisherige Version war zumindest so alt, dass sie es nicht konnte...)
Gerrit Codereview unterstützt es auch direkt, da muss ich aber erst noch rausfinden, wie man da das jeweilige Gerrit einrichtet.

Montag, 29. Oktober 2012

Qt, Git, Gerrit, ssh und Proxy. Teil 3. (Hooks)

Hat man das alles ans Laufen gebracht, funktioniert übrigens auch:
>scp -p BENUTZER@codereview.qt-project.org:hooks/commit-msg .git/hooks
Damit bekommt man dann die Git Hooks in sein eigenes Repository, die zwingend notwendig sind, damit die Commits eine eindeutige Id bekommen. Sonst muss man die von Hand runterladen und in den richtigen Ordner kopieren.