Results 1 to 6 of 6

Thread: Program crashes when adding QGraphicsEllipseItem to the scene

  1. #1
    Join Date
    Mar 2019
    Posts
    22
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

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


    This is Zeton.cpp


    This are Player's and Zeton's header files


    Game.cpp file


    Game.h file
    sf4.jpg


    Any help is appreciated !!!
    Last edited by MongKong; 2nd April 2019 at 21:33.

  2. #2
    Join Date
    Jul 2012
    Posts
    244
    Thanks
    27
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Program crashes when adding QGraphicsEllipseItem to the scene

    This doesnt work:

    Qt Code:
    1. class Player : public QObject, public QGraphicspolygonitem
    To copy to clipboard, switch view to plain text mode 

    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


    Qt Code:
    1. class Player : public QGraphicspolygonitem
    To copy to clipboard, switch view to plain text mode 

    as Qgraphicspolygonitem already inherits qobject.

  3. #3
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes when adding QGraphicsEllipseItem to the scene

    Quote Originally Posted by tuli View Post
    This doesnt work:

    Qt Code:
    1. class Player : public QObject, public QGraphicspolygonitem
    To copy to clipboard, switch view to plain text mode 

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




    so just do


    Qt Code:
    1. class Player : public QGraphicspolygonitem
    To copy to clipboard, switch view to plain text mode 

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

    Ginsengelf

  4. #4
    Join Date
    Mar 2019
    Posts
    22
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

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

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Program crashes when adding QGraphicsEllipseItem to the scene

    Quote Originally Posted by MongKong View Post
    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 View Post
    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,
    _

  6. #6
    Join Date
    Mar 2019
    Posts
    22
    Thanks
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default 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 !!

Similar Threads

  1. Not able to move QGraphicsEllipseItem on the scene
    By alex.agape94 in forum Qt Programming
    Replies: 3
    Last Post: 7th September 2017, 09:14
  2. Program crashes
    By Fallen_ in forum Qt Programming
    Replies: 49
    Last Post: 20th September 2010, 02:41
  3. Application crashes after adding a new class
    By wallace_000 in forum Newbie
    Replies: 1
    Last Post: 19th March 2010, 20:42
  4. adding QPixmap to scene
    By rogerholmes in forum Qt Programming
    Replies: 3
    Last Post: 6th June 2009, 06:45
  5. Adding item to scene
    By lni in forum Qt Programming
    Replies: 0
    Last Post: 21st April 2009, 18:28

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.