PDA

View Full Version : Registering non-static widget methods with PyMethodDef



devla
18th October 2012, 06:03
Hi everybody,

I am looking for a way to register non static methods of my MyWidget class as python methods.

MyWidget class is a QWidget class and it's on the main window. So I want to initialize
python when the app is launched then I want to retrive information from MyTableWidget (QTableWidget)
within MyWidget class. I like to register itemCount non-static method as python method. I could not do it
since non static object registration gives error on myPythonCommands below.

I checked boost:: python but could not find a way to do it. It's doc cover to create a python clas within
C++ but not his one as far as I know.

I was wondering if any of you know a way and point me to right direction?

Thank you very much




class MyTableWidget
{

};

class MyWidget
{

MyWidget()
{
Py_Initialize();
Py_InitModule("myApp", myPythonCommands);
}
~MyWidget()
{
Py_Finalize();
}

int itemCount()
{
return table.itemCount(); //return item count (in table) to python
}

MyTableWidget table;
};
static PyMethodDef myPythonCommands[] = {
{"itemCount", itemCount, METH_NOARGS, ""}, // here is the register part
{NULL, NULL, 0, NULL}
};