[PyQt] QDesktopServices::setUrlHandler does not have the right types

Phil Thompson phil at riverbankcomputing.com
Sun Oct 5 14:57:05 BST 2008


On Wed, 1 Oct 2008 17:58:38 -0700, "Erick Tryzelaar"
<idadesub at users.sourceforge.net> wrote:
> We ran into some trouble trying to get QDesktopServices::setUrlHandler
> and we tracked it down to a problem in pyqt4. setUrlHandler's source
> ultimately calls invokeMethod, which we managed to get to work in
> python, but we could only get setUrlHandler to work in c++. Looking at
> the sip source, we saw that the interface was different:
> 
> static SIP_PYOBJECT invokeMethod(QObject *obj, const char *member, ...)
> 
> vs.
> 
> static void setUrlHandler(const QString &scheme, SIP_RXOBJ_CON
> receiver, SIP_SLOT_CON(const QUrl &) method) [void (const QString
> &scheme, QObject *receiver, const char *method)];
> 
> So, in python you use it like this:
> 
> QMetaObject.invokeMethod(o, "openUrl", Qt.DirectConnection, Q_ARG("QUrl",
> url))
> QDesktopServices.setUrlHandler("foo", o, SLOT("openUrl"))
> QDesktopServices.setUrlHandler("foo", o.openUrl)
> 
> So as an experiment, we modified the sip setUrlHandler interface to:
> 
> static void setUrlHandler(const QString &scheme, QObject *receiver,
> const char *method);
> 
> And finally setUrlHandler worked, although it does have an ugly
interface:
> 
> QDesktopServices.setUrlHandler("foo", o, "openUrl")

This will be fixed in tonight's snapshot. You should be able to use either
("foo", o, "openUrl") or ("foo", o.openUrl).

Thanks,
Phil


More information about the PyQt mailing list