I have such code example
#include <QAbstractItemModel>
QAbstractItemModel* pSomeModel;
class A : public QObject
{
public:
A(){
connect(pSomeModel, &QAbstractItemModel::dataChanged, this, &A::foo);
}
protected slots:
virtual void foo(){};
};
class B : public A
{
public:
B(){}
void disconnectFoo() // calls for some extra reasons, when i do not need to accept model signals
{
disconnect(pSomeModel, &QAbstractItemModel::dataChanged, this, &A::foo); // cannot access protected member error
};
protected slots:
void foo() override {};
};
I’ve read some information about this problem and get that’s I can access only for protected member B::foo inside B. So I’ve tried to disconnect(pSomeModel, &QAbstractItemModel::dataChanged, this, &B::foo);
, but of course it doesn’t work correct, because it still call A::foo slot for model signal.
I can disconnect(model, signal, A, nullptr) and then connect(model, signal, B, foo) and it’s works correct, but it looks ugly. And It works only for such case with only one virtual slots, but what if I need some slots and don’t need to disconnect them. So how to properly disconnect such virtual slots?
CountingSheep777 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.