PDA

View Full Version : Program crashes when adding QGraphicsEllipseItem to the scene



MongKong
2nd April 2019, 20:27
Hello !!
I'm making a Four In a Row kinda game and i have problem spawning circles. When i press space i create an ellipse but when i try to add the thing to the scene my program just crashes...

This is Player.cpp where an object ( circle ) is created.
http://i65.tinypic.com/6gzjb4.jpg

This is Zeton.cpp
http://i67.tinypic.com/2qiydrm.jpg

This are Player's and Zeton's header files
http://i63.tinypic.com/2dtoint.png

Game.cpp file
http://i64.tinypic.com/311usco.png

Game.h file
13075


Any help is appreciated !!!

tuli
2nd April 2019, 20:42
This doesnt work:


class Player : public QObject, public QGraphicspolygonitem

https://doc.qt.io/qt-5/moc.html


Multiple Inheritance Requires QObject to Be First

If you are using multiple inheritance, moc assumes that the first inherited class is a subclass of QObject. Also, be sure that only the first inherited class is a QObject.


so just do



class Player : public QGraphicspolygonitem

as Qgraphicspolygonitem already inherits qobject.

Ginsengelf
3rd April 2019, 07:04
This doesnt work:


class Player : public QObject, public QGraphicspolygonitem

https://doc.qt.io/qt-5/moc.html




so just do



class Player : public QGraphicspolygonitem

as Qgraphicspolygonitem already inherits qobject.
No, it does not. QGraphicspolygonitem inherits QAbstractGraphicsShapeItem which inherits QGraphicsItem, but none of those is a QObject.

Ginsengelf

MongKong
3rd April 2019, 07:27
I forgot to say that, if i put 'this' as a parameter when creating an object Zeton the circle is spawned, but not on the right position and everytime my "player" moves left or right, circle moves with it aswell.

anda_skoa
3rd April 2019, 08:10
I'm making a Four In a Row kinda game and i have problem spawning circles. When i press space i create an ellipse but when i try to add the thing to the scene my program just crashes...

Access of invalid pointer?
Where do you set the global "game" variable?



This is Player.cpp where an object ( circle ) is created.

Please don't post screenshots of code, post the code.
It is simple text after all.

The board has code tags which will then take care of the formatting.

Cheers,
_

MongKong
3rd April 2019, 17:34
anda_skoa

In my previous Thread i posted the code, i forgot about those code tags this time tho, sorry. And after asking that question "Where do you set the global "game" variable?" i realized that i globally defined Game and then i redefined it again in the main function. Now it all works ! thanks !!