@@ -72,12 +72,23 @@ void PythonQt::init(int flags, const QByteArray& pythonQtModuleName)
7272{
7373 if (!_self) {
7474 _self = new PythonQt (flags, pythonQtModuleName);
75-
76- PythonQt::priv ()->setupSharedLibrarySuffixes ();
7775
7876 _self->_p ->_PythonQtObjectPtr_metaId = qRegisterMetaType<PythonQtObjectPtr>(" PythonQtObjectPtr" );
7977 PythonQtConv::registerMetaTypeToPythonConverter (_self->_p ->_PythonQtObjectPtr_metaId , PythonQtConv::convertFromPythonQtObjectPtr);
8078 PythonQtConv::registerPythonToMetaTypeConverter (_self->_p ->_PythonQtObjectPtr_metaId , PythonQtConv::convertToPythonQtObjectPtr);
79+ _self->_p ->_PythonQtSafeObjectPtr_metaId = qRegisterMetaType<PythonQtSafeObjectPtr>(" PythonQtSafeObjectPtr" );
80+ PythonQtConv::registerMetaTypeToPythonConverter (_self->_p ->_PythonQtSafeObjectPtr_metaId , PythonQtConv::convertFromPythonQtSafeObjectPtr);
81+ PythonQtConv::registerPythonToMetaTypeConverter (_self->_p ->_PythonQtSafeObjectPtr_metaId , PythonQtConv::convertToPythonQtSafeObjectPtr);
82+
83+ PythonQtObjectPtr importlib;
84+ importlib.setNewRef (PyImport_ImportModule (" importlib.machinery" ));
85+
86+ if (importlib) {
87+ _self->_p ->_pySourceFileLoader = importlib.getVariable (" SourceFileLoader" );
88+ _self->_p ->_pySourcelessFileLoader = importlib.getVariable (" SourcelessFileLoader" );
89+ }
90+
91+ PythonQt::priv ()->setupSharedLibrarySuffixes ();
8192
8293 PythonQtMethodInfo::addParameterTypeAlias (" QObjectList" , " QList<QObject*>" );
8394 qRegisterMetaType<QList<QObject*> >(" QList<void*>" );
@@ -302,6 +313,12 @@ PythonQt::PythonQt(int flags, const QByteArray& pythonQtModuleName)
302313 Py_Initialize ();
303314 }
304315
316+ #ifdef PYTHONQT_FULL_THREAD_SUPPORT
317+ if (!PyEval_ThreadsInitialized ()) {
318+ PyEval_InitThreads ();
319+ }
320+ #endif
321+
305322 // add our own python object types for qt object slots
306323 if (PyType_Ready (&PythonQtSlotFunction_Type) < 0 ) {
307324 std::cerr << " could not initialize PythonQtSlotFunction_Type" << " , in " << __FILE__ << " :" << __LINE__ << std::endl;
@@ -357,14 +374,6 @@ PythonQt::PythonQt(int flags, const QByteArray& pythonQtModuleName)
357374 Py_INCREF (&PythonQtStdInRedirectType);
358375
359376 initPythonQtModule (flags & RedirectStdOut, pythonQtModuleName);
360-
361- PythonQtObjectPtr importlib;
362- importlib.setNewRef (PyImport_ImportModule (" importlib.machinery" ));
363-
364- if (importlib) {
365- _p->_pySourceFileLoader = importlib.getVariable (" SourceFileLoader" );
366- _p->_pySourcelessFileLoader = importlib.getVariable (" SourcelessFileLoader" );
367- }
368377}
369378
370379PythonQt::~PythonQt () {
@@ -1084,7 +1093,7 @@ QVariant PythonQt::getNativeVariable(PyObject* object, const QString& objectname
10841093 QVariant result;
10851094 PythonQtObjectPtr obj = lookupObject (object, objectname);
10861095 if (obj) {
1087- result = QVariant::fromValue ( obj);
1096+ result = obj. toVariant ( );
10881097 }
10891098 return result;
10901099}
@@ -1708,6 +1717,14 @@ void PythonQt::setProfilingCallback(ProfilingCB* cb)
17081717}
17091718
17101719
1720+ void PythonQt::setEnableThreadSupport (bool flag)
1721+ {
1722+ #ifdef PYTHONQT_FULL_THREAD_SUPPORT
1723+ PythonQtGILScope::setGILScopeEnabled (flag);
1724+ PythonQtSlotInfo::setGlobalShouldAllowThreads (flag);
1725+ #endif
1726+ }
1727+
17111728static PyMethodDef PythonQtMethods[] = {
17121729 {NULL , NULL , 0 , NULL }
17131730};
@@ -2029,6 +2046,7 @@ bool PythonQtPrivate::isMethodDescriptor(PyObject* object) const
20292046
20302047const QMetaObject* PythonQtPrivate::getDynamicMetaObject (PythonQtInstanceWrapper* wrapper, const QMetaObject* prototypeMetaObject)
20312048{
2049+ PYTHONQT_GIL_SCOPE;
20322050 PythonQtDynamicClassInfo* info = wrapper->dynamicClassInfo ();
20332051 if (info) {
20342052 if (!info->_dynamicMetaObject ) {
0 commit comments