I found a way of getting Python extended widgets.<br>
<br>
I will post here the way I did and I would like to know if this is the right, easy and safer way of doing this:<br>
<br>
Supose this is a QWidget subclass and that I wrote a module called "MyWidget.py" with "MyWidget" class defined inside of it.<br>
<br>
<font style="font-family: courier new,monospace;" size="1">// let's assume that I've already created my QApplication in C++ code.<br>
SomeQWidgetClass::someMethod()<br>
{<br>
Py_Initialize();<br>
PyObject* __main__ = PyImport_AddModule("__main__");<br>
PyObject* scope = PyObject_GetAttrString(__main__, "__dict__"); <br>
PyRun_String("import sip", Py_single_input, scope, scope);<br>
PyRun_String("from PyQt4 import QtGui", Py_single_input, scope, scope);<br>
PyRun_String("import MyWidget", Py_single_input, scope, scope);<br>
<br>
// passing this widget as parent<br>
QString cmd = QString(<br>
"w = MyWidget.MyWidget(sip.wrapinstance(%1, QtGui.</font><font style="font-family: courier new,monospace;" size="1">SomeQWidgetClass</font><font style="font-family: courier new,monospace;" size="1">))"<br>
).arg((long)this);<br>
PyObject* w = PyRun_String(cmd.toStdString().c_str(), Py_single_input, scope, scope);<br>
if (!w) <br>
{<br>
PyErr_Print();<br>
}<br>
<br>
PyObject* id = PyRun_String("sip.unwrapinstance(w)", Py_eval_input, scope, scope); <br>
QWidget* widget = (QWidget*) </font><font style="font-family: courier new,monospace;" size="1">PyLong_AsLong(id)</font><font style="font-family: courier new,monospace;" size="1">;<br>
layout()->addWidget(widget);<br>
widget->show();<br>
}<br>
<br>
</font>Another thing I am worried about is memory management. Is there
any special care that should I take with those Python created objects?<br>
<br>
Thanks,<br>
<br>
--<br>
Eric Jardim<br>