Load a .so object with QLibrary from PyQt
-
jsulm Lifetime Qt Championreplied to ilian on 7 Jun 2017, 11:15 last edited by jsulm 6 Jul 2017, 11:18
@ilian What init function do you mean? Is it a function from your library? If so then sip.voidptr probably means that it could not resolve the function.
See http://doc.qt.io/qt-5.9/qlibrary.html#resolve, you need to export your functions to be able to resolve them. -
@jsulm I have an init function
extern "C" int init(int argc, char **argv) { QApplication a(argc, argv); MyWidget w; w.init(); return a.exec(); }
resolve()
returns a non null value, which issip.voidptr
, and I am expecting this to be aC
function pointer but, I have no idea how to call it. -
jsulm Lifetime Qt Championreplied to ilian on 7 Jun 2017, 12:23 last edited by jsulm 6 Jul 2017, 12:27
@ilian Please take a look at the link I posted before: you need to export your function, else it cannot be resolved.
You are aware that a.exec() will block until you close your app? That means init() call will block.
-
@ilian This void pointer is valid, but I don't know how to use it if it points to a function. Never did this with PyQt.
-
@jsulm I've made a similar C++ program with the function pointer, and it does what I want, open a widget and enters it's event loop. In short, as C++ program, loading the library everything is fine, as PyQt - it's not, or the reslove form PyQt and that sip.voidptr are some weird stuff, we know not of.
-
libc = CDLL('/home/ilian/git-projects/build-testpyqtlib-Desktop_Qt_5_7_1_GCC_64bit-Debug/libtestpyqtlib.so')
That line of code solved it all, just calledlibc.init(0, 0)
and the widget from the lib appeared... -
@ilian said in Load a .so object with QLibrary from PyQt:
sip.voidptr
this is not weird stuff :-)
It is documented, I just don't know how to use it if it contains a function pointer - I could not find anything in SIP documentation for this use case.
14/14