I can not share the map because it must be protected from simultaneously access at the same time something like this
{
//.......
return mMap.value(key);
}
int accessToMap(QString key)
{
QMutexLocker locker(&mutex);
//.......
return mMap.value(key);
}
To copy to clipboard, switch view to plain text mode
Either keep a pointer to the parent or share the map.
Do you mean keep pointer inside class and initialize it inside constructor?
class Child {
};
class Parent {
public:
Parent(Child * child) : mChild(child) {};
private:
Child * mChild;
};
class Child {
};
class Parent {
public:
Parent(Child * child) : mChild(child) {};
private:
Child * mChild;
};
To copy to clipboard, switch view to plain text mode
or use something like that
public:
Parent() {
child = new Child(this);
}
private:
Child *child;
};
public:
Parent* parent = qobject_cast<Parent*>(this->parent());
parent->accessToMap("somekey");
}
};
class Parent : public QObject{
public:
Parent() {
child = new Child(this);
}
int accessToMap(QString key) {};
private:
Child *child;
};
class Child : public QObject{
public:
Child(QObject *parent) : QObject(parent){};
void accessToMap(QString key ) {
Parent* parent = qobject_cast<Parent*>(this->parent());
parent->accessToMap("somekey");
}
};
To copy to clipboard, switch view to plain text mode
Bookmarks