[PyQt] Advices on embedding python in Qt/C++ application
Phil Thompson
phil at riverbankcomputing.com
Tue Sep 3 17:33:09 BST 2019
On 03/09/2019 17:23, Alexis Barbot wrote:
> Thanks Phil,
>
> I recompiled PyQt5.13 against Qt5.12 mingw32. I had to modify the qmake
> generated .pro to add "QMAKE_CXXFLAGE += "-D_hypot=hypot", and add
> "-lpython" to "LIBS" to every sub project, but it finally compiled. Now
> I'm
> trying to run an exemple as you said, but it crashes without
> explainations.
> Here is the code sample:
>
> #include <sip.h>
> #include <Python.h>
> #include <QDateTime>
>
> ...
>
> Py_Initialize();
> PyImport_ImportModule("sip");
You don't need this line ^^^^
> auto sipAPI_QtCore = reinterpret_cast<const
> sipAPIDef*>(PyCapsule_Import("PyQt5.sip._C_API", 0));
> PyImport_ImportModule("PyQt5.QtCore");
> auto type = sipAPI_QtCore->api_find_type("QDateTime");
>
> Could someone confirm me this example should work, please?
You should have error checking on each of the last 3 lines. If they are
working then debug it using whatever tools mingw provides.
Phil
More information about the PyQt
mailing list