Constructors (and destrucrtors) wrappers
Hi, again... There is a case where I have an object constructor that recieves the (int argc, char** argv) parameter from the main function: class QApplication { public: QApplication(int argc, char** argv) {...} ... }; int main(int argc, char** argv) { obj = new QApplication(argc, argv); ... } Is it possible to change the way it is constructed, just passing a list of args (the way of python does)
import sys import Qt app = Qt.QApplication(sys.argv) ...
I thinked some possibilities: * Creating a free function (or static method) with a factory role. But it could confuse the API... * Extending the class and reimplementing the constructor. I am afraid of this, because I do not know how extended objects will behave in python. Especially if some of them are constructed internally (in c++). The same question is applied to destructors. Any help and insights are welcome :) thanks, [Eric Jardim]
Eric Jardim <ericjardim@gmail.com> writes:
Hi, again...
There is a case where I have an object constructor that recieves the (int argc, char** argv) parameter from the main function:
class QApplication { public: QApplication(int argc, char** argv) {...} ... };
int main(int argc, char** argv) { obj = new QApplication(argc, argv); ... }
Is it possible to change the way it is constructed, just passing a list of args (the way of python does)
You might consider using make_constructor: http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/2065069 shows an example.
import sys import Qt app = Qt.QApplication(sys.argv) ...
I thinked some possibilities: * Creating a free function (or static method) with a factory role. But it could confuse the API... * Extending the class and reimplementing the constructor. I am afraid of this, because I do not know how extended objects will behave in python. Especially if some of them are constructed internally (in c++).
The same question is applied to destructors.
Hem. Well you can just use: .def("__del__", some_function ) where: void some_function(QApplication& x) { /*whatever*/ } HTH, -- Dave Abrahams Boost Consulting www.boost-consulting.com
On Tue, 29 Mar 2005 13:48:29 -0500, David Abrahams <dave@boost-consulting.com> wrote:
You might consider using make_constructor: http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/2065069 shows an example.
Funny, why I didn't saw this on the docs? :) Anyway, is that bug, comented on your reply, corrected on the newest version (1.32)?
Hem. Well you can just use: .def("__del__", some_function ) where: void some_function(QApplication& x) { /*whatever*/ }
Sure... I tried that before, but I thought that it was too hacky :) I was afraid of overrinding the original destructor or something... I am playing with the Qt3 libraries, just for fun (I know that exists PyQt) and for learning Boost.Python. Soon I will show my homework :) Thanks again, David [Eric Jardim]
Eric Jardim <ericjardim@gmail.com> writes:
On Tue, 29 Mar 2005 13:48:29 -0500, David Abrahams <dave@boost-consulting.com> wrote:
You might consider using make_constructor: http://aspn.activestate.com/ASPN/Mail/Message/c++-sig/2065069 shows an example.
Funny, why I didn't saw this on the docs? :)
Anyway, is that bug, comented on your reply, corrected on the newest version (1.32)?
I think so.
Hem. Well you can just use: .def("__del__", some_function ) where: void some_function(QApplication& x) { /*whatever*/ }
Sure... I tried that before, but I thought that it was too hacky :) I was afraid of overrinding the original destructor or something...
Why don't you try it and see what happens? Put a printf in your destructor and see if it gets called. -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (2)
-
David Abrahams -
Eric Jardim