@@ -612,9 +612,9 @@ QImage *PythonWrapper::toQImage(PyObject *pyobj)
612
612
Py::Object PythonWrapper::fromQIcon (const QIcon* icon)
613
613
{
614
614
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
615
- const char * typeName = typeid (*const_cast <QIcon*>(icon)).name ();
616
615
auto type = getPyTypeObjectForTypeName<QIcon>();
617
616
if (type) {
617
+ const char * typeName = typeid (*const_cast <QIcon*>(icon)).name ();
618
618
PyObject* pyobj = Shiboken::Object::newObject (type, const_cast <QIcon*>(icon), true , false , typeName);
619
619
return Py::asObject (pyobj);
620
620
}
@@ -636,14 +636,18 @@ QIcon *PythonWrapper::toQIcon(PyObject *pyobj)
636
636
Py::Object PythonWrapper::fromQDir (const QDir& dir)
637
637
{
638
638
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
639
- const char * typeName = typeid (dir).name ();
640
639
auto type = getPyTypeObjectForTypeName<QDir>();
641
640
if (type) {
641
+ const char * typeName = typeid (dir).name ();
642
642
PyObject* pyobj = Shiboken::Object::newObject (type, const_cast <QDir*>(&dir), false , false , typeName);
643
643
return Py::asObject (pyobj);
644
644
}
645
645
#else
646
- Q_UNUSED (dir)
646
+ // Access shiboken/PySide via Python
647
+ Py::Object obj = qt_wrapInstance<const QDir*>(&dir, " QDir" , " QtGui" );
648
+ if (!obj.isNull ()) {
649
+ return obj;
650
+ }
647
651
#endif
648
652
throw Py::RuntimeError (" Failed to wrap directory" );
649
653
}
@@ -713,32 +717,23 @@ Py::Object PythonWrapper::fromQObject(QObject* object, const char* className)
713
717
if (!object) {
714
718
return Py::None ();
715
719
}
720
+ const char * typeName;
721
+ if (className) {
722
+ typeName = className;
723
+ }
724
+ else {
725
+ typeName = object->metaObject ()->className ();
726
+ }
716
727
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
717
728
// Access shiboken/PySide via C++
718
729
auto type = getPyTypeObjectForTypeName<QObject>();
719
730
if (type) {
720
- std::string typeName;
721
- if (className) {
722
- typeName = className;
723
- }
724
- else {
725
- typeName = object->metaObject ()->className ();
726
- }
727
-
728
- PyObject* pyobj = Shiboken::Object::newObject (type, object, false , false , typeName.c_str ());
731
+ PyObject* pyobj = Shiboken::Object::newObject (type, object, false , false , typeName);
729
732
WrapperManager::instance ().addQObject (object, pyobj);
730
733
return Py::asObject (pyobj);
731
734
}
732
735
#else
733
736
// Access shiboken/PySide via Python
734
- std::string typeName;
735
- if (className) {
736
- typeName = className;
737
- }
738
- else {
739
- typeName = object->metaObject ()->className ();
740
- }
741
-
742
737
Py::Object obj = qt_wrapInstance<QObject*>(object, typeName, " QtCore" );
743
738
if (!obj.isNull ()) {
744
739
return obj;
@@ -749,32 +744,23 @@ Py::Object PythonWrapper::fromQObject(QObject* object, const char* className)
749
744
750
745
Py::Object PythonWrapper::fromQWidget (QWidget* widget, const char * className)
751
746
{
747
+ const char * typeName;
748
+ if (className) {
749
+ typeName = className;
750
+ }
751
+ else {
752
+ typeName = widget->metaObject ()->className ();
753
+ }
752
754
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
753
755
// Access shiboken/PySide via C++
754
756
auto type = getPyTypeObjectForTypeName<QWidget>();
755
757
if (type) {
756
- std::string typeName;
757
- if (className) {
758
- typeName = className;
759
- }
760
- else {
761
- typeName = widget->metaObject ()->className ();
762
- }
763
-
764
- PyObject* pyobj = Shiboken::Object::newObject (type, widget, false , false , typeName.c_str ());
758
+ PyObject* pyobj = Shiboken::Object::newObject (type, widget, false , false , typeName);
765
759
WrapperManager::instance ().addQObject (widget, pyobj);
766
760
return Py::asObject (pyobj);
767
761
}
768
762
#else
769
763
// Access shiboken/PySide via Python
770
- std::string typeName;
771
- if (className) {
772
- typeName = className;
773
- }
774
- else {
775
- typeName = widget->metaObject ()->className ();
776
- }
777
-
778
764
Py::Object obj = qt_wrapInstance<QWidget*>(widget, typeName, " QtWidgets" );
779
765
if (!obj.isNull ()) {
780
766
return obj;
0 commit comments