Results 1 to 4 of 4

Thread: QGraphicsViews & QGraphicsScenes. How many can I use at once?

  1. #1
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QGraphicsViews & QGraphicsScenes. How many can I use at once?

    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)
    Qt Code:
    1. void MainWindow::title()
    2. {
    3. ui->graphicsView_2->setSceneRect(0, 0, 274, 92);
    4. titleScene.setSceneRect(0, 0, 274, 92);
    5.  
    6. titleScene.clear();
    7.  
    8. static const char * SP[] =
    9. { ":/pics/spin/title00.gif", ":/pics/spin/title01.gif", ":/pics/spin/title02.gif", ":/pics/spin/title03.gif",
    10. ":/pics/spin/title04.gif", ":/pics/spin/title05.gif", ":/pics/spin/title06.gif", ":/pics/spin/title07.gif",
    11. ":/pics/spin/title08.gif", ":/pics/spin/title09.gif", ":/pics/spin/title10.gif", ":/pics/spin/title11.gif",
    12. ":/pics/spin/title12.gif", ":/pics/spin/title13.gif", ":/pics/spin/title14.gif", ":/pics/spin/title15.gif",
    13. ":/pics/spin/title16.gif", ":/pics/spin/title17.gif", ":/pics/spin/title18.gif", ":/pics/spin/title19.gif" };
    14.  
    15.  
    16.  
    17. QPixmap s(SP[spinCount]);
    18. titleScene.addPixmap(s);
    19.  
    20. ui->graphicsView_2->setScene(& titleScene);
    21.  
    22.  
    23. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsViews & QGraphicsScenes. How many can I use at once?

    What exactly is your program crashing on?
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsViews & QGraphicsScenes. How many can I use at once?

    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...

  4. #4
    Join Date
    Mar 2010
    Posts
    86
    Thanks
    11
    Thanked 7 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QGraphicsViews & QGraphicsScenes. How many can I use at once?

    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.

Similar Threads

  1. Scrolling 2 QGraphicsViews with 1 scrollbar
    By dentist in forum Newbie
    Replies: 2
    Last Post: 14th April 2010, 03:12
  2. Multiple QGraphicsViews with one QGraphicsScene
    By alisami in forum Qt Programming
    Replies: 3
    Last Post: 22nd March 2010, 04:02
  3. Replies: 3
    Last Post: 3rd February 2009, 00:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.