Hmmm… You're doing things pretty similarly to my code there, and I would have expected those dir commands to show "run" as you say. The only significant difference I've spotted is that you're calling PythonQt::registerCPPClass(), whereas I'm calling PythonQt::registerClass(). That might make a difference, given that PythonQt wraps QObject classes and general C++ classes in different ways. Does changing that help at all?
- Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello!
I need a class in python that can be created on some circumstances:
and, on other circumstances, I want it to be created for the user prior to first line of the custom script:
The way I understand the examples, this means that:
- for first use case I need a wrapper:
- for second use case I need my class to inherit QObject:
Is there any other way?
PS there may be syntactic errors in code up there, I didn't checked it. Just extract the idea. :)
Hi Nick,
The way I do this is using PythonQt's decorators. Here's a rough example from some code:
class Test : public QObject
{
Q_OBJECT
public slots:
void run();
};
class TestDecorator : public QObject
{
Q_OBJECT
public slots:
Test* new_Test();
};
Provided that you register the decorators and then the class before you use either of them, this should let you do any of the following:
test1 = my_module.getSomeTest()
test1.run()
test2 = my_module.Test() # you'll need to copy this from PythonQt.private
test2.run()
Hope that helps.
- Chris
Thank you for your help, Chris! There is something that I'm missing here. A little example may help.
This is how I define the classes that you have used (minimal changes):
Now here is the code that makes use of these classes. There are comments indicating the output and the missing routine:
Hmmm… You're doing things pretty similarly to my code there, and I would have expected those dir commands to show "run" as you say. The only significant difference I've spotted is that you're calling PythonQt::registerCPPClass(), whereas I'm calling PythonQt::registerClass(). That might make a difference, given that PythonQt wraps QObject classes and general C++ classes in different ways. Does changing that help at all?
- Chris
that's right, that was the problem. Thank you, Chris!
For future reference, the line
should be replaced with this one:
Nick