PDA

View Full Version : QGraphicsViews & QGraphicsScenes. How many can I use at once?



budda
2nd August 2010, 00:45
my question is general in respects to a program I am working on. I got into the habit of making multiple QGraphicsViews in a single program, with the form in the mainwindow.ui and then I use QGraphicsScene along with them. Usually this is because of a 3d text animation or some other such sprite. Which is usually stationary. Is having smaller multiple views not efficient on memory? Compared to one large GraphicsView? My game I have going now, is running 4 different ones, and apparently it just started crashing after adding the 4th one. The pics themselves donot exceed the 10mg pixmap cache at all, but it is still crashing. Just wondering if I could get any tips on this. And some tidbits about scene magement would be useful. I'm not too certain about refreshing a scene, and think that I am wastefully reinitializing the whole thing over and over again.

for instance this method function is being called from a eventTimer method function and produces a spinning graphics through all of the pics. ( there is a pause on how often it this is repeatedly called and spinCount is a global int that is incremented during the timed animation)


void MainWindow::title()
{
ui->graphicsView_2->setSceneRect(0, 0, 274, 92);
titleScene.setSceneRect(0, 0, 274, 92);

titleScene.clear();

static const char * SP[] =
{ ":/pics/spin/title00.gif", ":/pics/spin/title01.gif", ":/pics/spin/title02.gif", ":/pics/spin/title03.gif",
":/pics/spin/title04.gif", ":/pics/spin/title05.gif", ":/pics/spin/title06.gif", ":/pics/spin/title07.gif",
":/pics/spin/title08.gif", ":/pics/spin/title09.gif", ":/pics/spin/title10.gif", ":/pics/spin/title11.gif",
":/pics/spin/title12.gif", ":/pics/spin/title13.gif", ":/pics/spin/title14.gif", ":/pics/spin/title15.gif",
":/pics/spin/title16.gif", ":/pics/spin/title17.gif", ":/pics/spin/title18.gif", ":/pics/spin/title19.gif" };



QPixmap s(SP[spinCount]);
titleScene.addPixmap(s);

ui->graphicsView_2->setScene(& titleScene);


}

franz
2nd August 2010, 07:00
What exactly is your program crashing on?

budda
2nd August 2010, 09:38
I think it was trying to access an out of bounds element of the array. spot SP[20] when it only goes up to SP[19]. it is no longer crashing, as my incrementing was happening before calling the array not after. But I would still like some feedback about using multiple QGraphicsView/QGraphicsScene ( say like 200pixels by 50pixels for one animation sprite and loading the Pixmaps like the above code ) verses using just one large QGraphicsView/QGraphicsScene and having it handle all the refresh events of all the sprites...

budda
2nd August 2010, 11:12
I guess my question is, how much memory resources does using the form ui document drop in QGraphicsView use? Is having many smaller ones better for clearing scenes and refreshing them if I have multiple animations going on, I use one event timer and boolean on/off switches for these individual sprites. Or should I be just using one QGraphicsView with QGraphicsItems w/ setPos(x,y); 's The sprites are not really in the area of the largest QGraphicsView and by having a few of these smaller ones, that are exactly the size of each individual picture of a frame in an animation sprite, I don't have to add an instance of QGraphicsItem for each one.... just trying to do things with the smallest memory useage. And I haven't seen much on this subject.