[PyQt] Qt message handler has wrong signature with Qt5

Phil Thompson phil at riverbankcomputing.com
Wed Apr 3 01:17:09 BST 2013


On Wed, 03 Apr 2013 00:16:49 +0100, Baz Walter <bazwal at ftml.net> wrote:
> Hello
> 
> For Qt4, QtCore.qInstallMsgHandler installs a Qt message handler with 
> the following signature:
> 
>      void myMsgHandler(QtMsgType, const char *);
> 
> Using PyQt4 with Qt4, this correctly results in the second argument 
> being passed as a python bytes object (for both the v1 and v2 apis).
> 
> However, for Qt5 it only does this when using Python3 with the v2 api. 
> For Python3 with the v1 api, it passes a QString, and for Python2 it 
> either passes a QString (v1 api) or a python unicode object (v2 api).
> 
> I realize that QtCore.qInstallMsgHandler has been deprecated in Qt5, but

> it would still be great if this could be fixed at some point.
> 
> Simple test script:
> 
>      import sys, sip
>      sip.setapi('QString', int(sys.argv[1]) if sys.argv[1:] else 1)
>      from PyQt4 import QtGui, QtCore
> 
>      app = QtGui.QApplication([])
> 
>      def handler(kind, msg):
>          print('API v%s: %s, %s' % (
>              sip.getapi('QString'), type(kind), type(msg)))
> 
>      QtCore.qInstallMsgHandler(handler)
>      app.desktop().screenGeometry(None)

As the Qt5 message handler is passed a QString rather than the Qt4 char *
I think the current behaviour is the right one. Qt5 is not Qt4 so PyQt4
built against Qt5 is not going to have the same API as PyQt4 built against
Qt4.

Phil


More information about the PyQt mailing list