Answer the question
In order to leave comments, you need to log in
What is the right way to write a macro to "extend" parent methods?
You need to create many descendants from different types, all of these types are descendants of QObject and QWidget. The task of the heir is to replace the standard methods, but leave the possibility of referring to them (only to himself). Here is one of the classes that should "extend" or override the parent() and setParent() methods:
class PQ_QWidget : public QWidget {
Q_OBJECT
PQW_OBJECT
public:
explicit PQ_QWidget(QWidget* parent = 0) :
QWidget(parent){
}
~PQ_QWidget(){
delete this;
}
};
#define PQW_OBJECT \
Q_PROPERTY( long parent READ parent WRITE setParent ) \
public: \
Q_INVOKABLE long parent() {\
return m_parentQPId;\
}\
public Q_SLOTS:\
Q_INVOKABLE void setParent(long parentQPId) {\
QWidget *qo = (QWidget*) ObjectFactory::getQObject(parentQPId);\
if(qo != NULL) {\
m_parentQPId = parentQPId;\
setParent(qo);\
}\
}\
private:\
long m_parentQPId;
#define PQW_OBJECT \
Q_PROPERTY( long parent READ parent WRITE setParent ) \
public: \
Q_INVOKABLE long parent() {\
return m_parentQPId;\
}\
public Q_SLOTS:\
Q_INVOKABLE void setParent(long parentQPId) {\
QWidget *qo = (QWidget*) ObjectFactory::getQObject(parentQPId);\
if(qo != NULL) {\
m_parentQPId = parentQPId;\
QWidget::setParent(qo);\
}\
}\
private:\
long m_parentQPId;
Answer the question
In order to leave comments, you need to log in
Make working sample classes first, and then cut them into macros, but on the other hand, C ++ has multiple inheritance, including non-virtual, why not use them. I just don’t know qt, but what your macros look like, they’re just asking for separate impurity classes, and some dependent parts can be thrown into a template parameter, you can use CRTP.
1. Have you tried using your first option without a macro? What does the compiler say? Is the error coming from the moc file?
2. I would advise you a template parent, but since you have an MOC, it won't work.
3. Well, pass the parameter to the macro, if nothing at all. I would still figure out first why the option without specifying the genus. class does not work.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question