PDA

View Full Version : truncate my declaration of QGraphicsItem



wagmare
21st July 2009, 11:57
i have QGraphicsItem()
class GpioItem

i want to add 28 item of it to add in the scene

in the view.h
i am adding like this

GpioItem *button1;
GpioItem *button2;
GpioItem *button3;
.
.
.
.
.
GpioItem *button23;
GpioItem *button24;

and the .h file becomes too lengthy ... how to define all the 28 items in a short way of coding c++ ...

Lykurg
21st July 2009, 14:08
What's about
private:
QList<GpioItem *> m_items;
//...
//c-tor
for (int i=0; i<24; ++i)
{
GpioItem *it = new GpioItem();
// do some stuff with it
m_items.append(it);
scene->addItem(it);
}

// access it via
m_item.at(0)->setPos(...); //...