<div dir="ltr"><div dir="ltr">I looked at it, but it seems I didn't catch the point (or possibly the moment I read it I did not figure out it could be what I needed...). I now understand that it explains I should get the c api dynamically to call it, whereas I was trying to call static method. I could get something roughtly working this way, with pyqt compiled in static (see code below). I'm currently trying to clean everythind, but I realized I had to upgrade Qt for that, as I can't find a PyQt package for Qt5.9 (sad, as it's a LTS). So I'll keep you updated on my progress.</div><div>In my tests I realized something: is there some special care to do with containers while passing from C++/python? In my first attemp to pass a QVariantMap the items added after SetItem to python are not visible from python? (and items modified in python are not modified in c++). Any special thoughts about this?</div><div>Thanks for all your help</div><div><br></div><div>Alexis<br></div><div dir="ltr"><br></div><div dir="ltr">```</div><div>Py_Initialize();</div><div>PyEval_InitThreads();<br></div><div>auto sipModule = PyImport_ImportModule("sip");</div><div>
PyImport_ImportModule("PyQt5.sip"); <br></div><div></div><div>auto sipAPI = (const sipAPIDef*)PyCapsule_Import("sip._C_API", 0);</div><div>PyCapsule_Import("PyQt5.QtCore._C_API", 0);<br></div><div></div><div>auto sipModuleDict = PyModule_GetDict(sipModule);</div><div></div><div>auto sip_sipmod = PyImport_ImportModule("PyQt5.sip"); <br></div><div>auto sip_capiobj = PyDict_GetItemString(PyModule_GetDict(sip_sipmod), "_C_API");</div><div><br></div><div>sipAPI_QtCore = reinterpret_cast<const sipAPIDef*>(PyCapsule_GetPointer(sip_capiobj, "PyQt5.sip._C_API"));</div><div>qpycore_init();</div><div>sipExportModule(&sipModuleAPI_QtCore, SIP_API_MAJOR_NR, SIP_API,MINOR_NR, 0);</div><div><br></div><div>auto m = PyImport_AddModule("__main__");</div><div>auto g = PyModule_GetDict(m);</div><div>auto d = PyDictNew();</div><div><br></div><div>auto test = std::make_unique<QDateTIme>(QDateTIme::currentDateTime);</div><div>auto type = sipAPI_QtCore->api_find_type("QDateTime);</div><div>auto pyTest = sipAPI_QtCore->api_convert_from_type(test.get(), type, nullptr);</div><div>// Ici je visualise l'objet C++ en python<br></div><div>PyDict_SetItem(d, PyUnicode_FromString("testdate"), Py_file_input, g, d);</div><div>PyRun_String("print(testdate.toString())", Py_file_input, g, d);</div><div>test->setDate(QDate{2000,02,03});</div><div>
<div>// Ici je visualise en python que l'objet a été modifié en c++<br></div><div>PyDict_SetItem(d, PyUnicode_FromString("testdate"), Py_file_input, g, d);</div>
</div><div>Py_FinalizeEx();<br></div><div dir="ltr">```<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Le mar. 27 août 2019 à 11:48, Phil Thompson <<a href="mailto:phil@riverbankcomputing.com" target="_blank">phil@riverbankcomputing.com</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Have you read this...<br>
<br>
<a href="https://www.riverbankcomputing.com/static/Docs/sip/embedding.html" rel="noreferrer" target="_blank">https://www.riverbankcomputing.com/static/Docs/sip/embedding.html</a><br>
<br>
On 27/08/2019 09:45, Alexis Barbot wrote:<br>
> What do you mean? Should I import this module in the python context? I<br>
> tried adding this line wihtout any effect:<br>
> `PyRun_SimpleString("import PyQt5.QtCore")`<br>
> <br>
> If we're speaking about some cpp header to include, I can't see which <br>
> one<br>
> it is.<br>
> Thanks<br>
> <br>
> Le mar. 27 août 2019 à 10:25, Phil Thompson <br>
> <<a href="mailto:phil@riverbankcomputing.com" target="_blank">phil@riverbankcomputing.com</a>> a<br>
> écrit :<br>
> <br>
>> On 27/08/2019 08:29, Alexis Barbot wrote:<br>
>> > Thanks for these replies,<br>
>> ><br>
>> > First of all, I had a look at PythonQt which indeed looked promising in<br>
>> > my<br>
>> > case. However I had toubles to build it, so I skipped that solution.<br>
>> > Now I<br>
>> > understand that this was probably caused by the compilation attempt<br>
>> > with<br>
>> > mingw while using a binary python installer, obviously compiled using<br>
>> > msvc.<br>
>> > Furthermore, I got some success with PyQt: after preparing all paths<br>
>> > and<br>
>> > adding several flags to the configure command, I could perform the<br>
>> > complete<br>
>> > build wihtout errors. I so tried to write a small piece of code to<br>
>> > validate<br>
>> > my usage. It builds correctly, but it suddenly stop while running<br>
>> > without<br>
>> > any error message. Here is the code:<br>
>> ><br>
>> > ```<br>
>> > #include <QDebug><br>
>> > #include <Python.h><br>
>> > #include <QDateTime><br>
>> > #include <sipAPIQtCore.h><br>
>> > #include <memory><br>
>> ><br>
>> > int main(int argc, char* argv[])<br>
>> > {<br>
>> > qDebug() << "start";<br>
>> > Py_Initialize();<br>
>> > auto d = PyDict_New();<br>
>> > auto test = std::make_unique<QDateTime>();<br>
>> > auto pyTest = sipConvertFromType(test.get(), sipType_QDateTime,<br>
>> > nullptr);<br>
>> > qDebug() << "end";<br>
>> > Py_FinalizeEx();<br>
>> > return 0;<br>
>> > }<br>
>> > ```<br>
>> ><br>
>> > It sounds like everything is installed but I'm missing some<br>
>> > initialization<br>
>> > step. Is that possible? Or maybe there's something else I should<br>
>> > check/try?<br>
>> > Many thanks for your help.<br>
>> <br>
>> You haven't imported PyQt5.QtCore.<br>
>> <br>
>> Phil<br>
>> <br>
> <br>
> _______________________________________________<br>
> PyQt mailing list <a href="mailto:PyQt@riverbankcomputing.com" target="_blank">PyQt@riverbankcomputing.com</a><br>
> <a href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt" rel="noreferrer" target="_blank">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a><br>
</blockquote></div></div>