PDA

View Full Version : QLibrary in PyQt



Urthas
30th October 2009, 18:46
Hi there,

The PyQt docs for QLibrary include the following common-usage snippet:



QLibrary myLib("mylib");
typedef void (*MyPrototype)();
MyPrototype myFunction = (MyPrototype) myLib.resolve("mysymbol");
if (myFunction)
myFunction();


That is not terribly useful, as is, within Python. What I'm wondering is what the Python equivalent would be? This is what I've tried:



def getKeyboardHooks(self):
kcLib = QLibrary('path\to\my.dll')
f = kcLib.resolve('installhook')
if not f:
print 'DEBUG: no resolve() installhook', kcLib.errorString()
else:
print 'DEBUG:', f
try:
f(self.winId())
except Exception as (errstr):
logger.exception(errstr)


On STDOUT I get the else print statement, and the log file gets the following exception: "TypeError: 'sip.voidptr' object is not callable". It seems I need the Python equivalent of a typedef cast but I have no idea how to do this. Web searches on Python typedef and sip.voidptr have yielded very little information, although there is a sip.cast(obj, type) method that looks promising? I don't know. Thanks in advance to any PyQt coders who respond.