发出的信号不会在派生类中捕获(emitted signal is not caught in derived class)
class Settings : public QObject
{
Q_OBJECT
public:
Settings();
~Settings();
void setValue(QString key, QVariant value);
// [...]
signals:
void settingsChanged();
// [...]
class ApplicationSettings : public Settings
{
public:
explicit ApplicationSettings();
~ApplicationSettings();
public slots:
void save();
// [...]
每次我通过基类中的setvalue(...)更改值时,我都会emit settingsChanged() 。
在ApplicationSettings的构造函数中,我说:
connect(this, SIGNAL(settingsChanged()), this, SLOT(save()));但是从不调用save() 。
class Settings : public QObject { Q_OBJECT public: Settings(); ~Settings(); void setValue(QString key, QVariant value); // [...] signals: void settingsChanged(); // [...] class ApplicationSettings : public Settings { public: explicit ApplicationSettings(); ~ApplicationSettings(); public slots: void save(); // [...]Every time I change a value via setvalue(...)in the base class, I do emit settingsChanged().
In the constructor of ApplicationSettings I say:
connect(this, SIGNAL(settingsChanged()), this, SLOT(save()));But save() is never called.
最满意答案
正如我一直在写这个问题,我注意到我的派生类中没有包含Q_OBJECT 。 添加此信号,信号连接正确。 我认为这个问题对其他人来说可能仍然有用,因为对我来说,基类的Q_OBJECT -macro不是“继承”也是新的。
As I've been writing this question I noticed that I did not include Q_OBJECT in my derived class. Adding this, the signal was connected correctly. I think this question may still be useful for others, because it was also new for me that the Q_OBJECT-macro of the base class is not "inherited".
更多推荐
发布评论