发出的信号不会在派生类中捕获(emitted signal is not caught in derived class)

编程入门 行业动态 更新时间:2024-10-28 02:23:52
发出的信号不会在派生类中捕获(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".

更多推荐

本文发布于:2023-08-02 06:18:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1370044.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:会在   类中   信号   emitted   class

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!