From kde-games-devel Wed Dec 12 20:43:29 2001 From: Andreas Beckermann Date: Wed, 12 Dec 2001 20:43:29 +0000 To: kde-games-devel Subject: [Kde-games-devel] Re: QCanvasSprite + QObject X-MARC-Message: https://marc.info/?l=kde-games-devel&m=100818972508558 On Wednesday 12 December 2001 20:08, Johnny Andersson wrote: > Hi. Hi > Is it possible to inherit from both QCanvasSprite and QObject at the > same time? Yes, this is possible - at least IIRC. Boson did this once. > My program doesn't compile when I do. I've written my own sprite Why? Can you post the error message= > class, derived from QObject. I started having trouble when I wanted to use > collision detection; to use RTTI, I have to derive from QCanvasItem. > > As a temporary solution, I created a small class derived form QCanvasSprite > with the rtti-stuff. This class contains a pointer to my "real" sprite > object, so that I can find it when Qt reports a collision. An ugly hack. Well, my test code compiles: Header: #include #include class A : public QObject, QCanvasSprite { public: A() : QObject(0), QCanvasSprite(0,0) { } ~A() { } }; This doesn't do anything useful though. You'll also need to add a rtti() to be able to use this at all. But it compiles here. > Is it just me, or does the QCanvas extension not feel as polished as the > rest of Qt? While very useful, there are some things that I've had to > re-design in my program to work around. For example, QCanvasPixmapArray has > a method setImage(...) to set a specific image in the list, and if needed, > it extends the list. But I can't create an empty QCanvasPixmapArray and > then add items to it using setImage, I have to create a dummy array first > *or* create an empty QCanvasPixmapArray and then call readPixmaps (which if > of course only relevant if you have the graphics in a file, and not > generate them yourself). WHat about this: QValueList pixmapList; for(int i = 0; i < pixmaps; i++) { QPixmap p = loadPixmap(i); pixmapList.push_back(p); // aka append() } QCanvasPixmapArray* pixmapArray = new QCanvasPixmapArray(pixmapList); if (!pixmapArray->isValid()) { return false; } // ... This pixmapArray can now be used by you. This is the way we do it in boson - the pixmapArray is stored as a pointer so that we can use it for all units of this type and don't have to reload it again. Remember to delete the pointer. CU Andi _______________________________________________ kde-games-devel mailing list kde-games-devel@mail.kde.org http://mail.kde.org/mailman/listinfo/kde-games-devel