PDA

View Full Version : qt signal defined in macro



TorAn
12th August 2018, 02:11
I defined the signal in the macro:


#define PROP_SINGLEVAL(prpname) \
private: \
int _##prpname; \
public: \
int& prpname () {return _##prpname;}; \
const int& ##prpname() const {return _##prpname;}; \
signals: \
void on##prpname##Change();

class options : public QObject
{
Q_OBJECT
public:
options();

PROP_SINGLEVAL(val)
};

It compiles but, when trying to connect the signal to the slot of another object instance, the message is that the signal on options::onvalChange() does not exist. I think I understand the reason for it (moc preprocessing does not expand the macro). Perhaps there is a way to make it work? I have many variables and for each one I want to provide the signal when it is changing.
Thanks.

Added after 7 minutes:

Can't find the way to delete the post, hence the answer: Q_SIGNAL

wysota
16th August 2018, 07:43
Why not use Q_PROPERTY with MEMBER and NOTIFY and let Qt do all the magic for you?