1 Attachment(s)
Program crashes when adding QGraphicsEllipseItem to the scene
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
Attachment 13075
Any help is appreciated !!!
Re: Program crashes when adding QGraphicsEllipseItem to the scene
This doesnt work:
Code:
class Player
: public QObject,
public QGraphicspolygonitem
https://doc.qt.io/qt-5/moc.html
Quote:
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
Code:
class Player : public QGraphicspolygonitem
as Qgraphicspolygonitem already inherits qobject.
Re: Program crashes when adding QGraphicsEllipseItem to the scene
Quote:
Originally Posted by
tuli
This doesnt work:
Code:
class Player
: public QObject,
public QGraphicspolygonitem
https://doc.qt.io/qt-5/moc.html
so just do
Code:
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
Re: Program crashes when adding QGraphicsEllipseItem to the scene
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.
Re: Program crashes when adding QGraphicsEllipseItem to the scene
Quote:
Originally Posted by
MongKong
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?
Quote:
Originally Posted by
MongKong
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,
_
Re: Program crashes when adding QGraphicsEllipseItem to the scene
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 !!