[PyQt] Qt message handler has wrong signature with Qt5
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:
> 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) 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)))
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
More information about the PyQt