Hi,
I have a class which contains two objects whose classes are both derived from QGraphicsItem. I would like to reach them outside without setting these members public. In codes speaking it is something like this:
class myClass
{
public: // ... and here I need some functions like getVar1() or getVat2()
private:
// ...
c1 * var1; // c1 : public QGraphicsItem
c2 * var2; // c2 : public QGraphicsItem
}
class myClass
{
public: // ... and here I need some functions like getVar1() or getVat2()
private:
// ...
c1 * var1; // c1 : public QGraphicsItem
c2 * var2; // c2 : public QGraphicsItem
}
To copy to clipboard, switch view to plain text mode
It could be also fine to get them in a QGraphichScene object, but a function like below does not work because the copy constructor is private.
{
temp.addItem(var1);
temp.addItem(var2);
return temp;
}
QGraphicsScene myClass::getMyScene()
{
QGraphicsScene temp;
temp.addItem(var1);
temp.addItem(var2);
return temp;
}
To copy to clipboard, switch view to plain text mode
I've also tried this:
{
sc.addItem(var1);
}
void setMyScene(QGraphicsScene & sc)
{
sc.addItem(var1);
}
To copy to clipboard, switch view to plain text mode
but this does not seem to do anything to a "QGraphicsScene scene" variable. Frankly speaking it work like this:
di->setMyScene(scene[0]);
ui->graphicsView->setScene(scene);
QGraphicsScene * scene = new QGraphicsScene;
di->setMyScene(scene[0]);
ui->graphicsView->setScene(scene);
To copy to clipboard, switch view to plain text mode
But this solution does not really look correct to me. Well, works, but still...
What would you suggest?
Bookmarks