Results 1 to 6 of 6

Thread: Confusing SIGSEV

  1. #1
    Join Date
    May 2007
    Location
    Warsaw, Poland
    Posts
    52
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Confusing SIGSEV

    Qt Code:
    1. #ifndef PAWNBOX_SAFETY_DECLARATION
    2. #define PAWNBOX_SAFETY_DECLARATION
    3. class QPixmap;
    4. #include <QWidget>
    5. #include <QRectF>
    6. #include <QColor>
    7. #include <QMap>
    8.  
    9. namespace MTRUTIL {
    10. const int AMOUNT_OF_PAWNS = 7;
    11. }
    12.  
    13. namespace MTR {
    14. class PawnBox : public QWidget {
    15. Q_OBJECT
    16. public:
    17. PawnBox(QWidget *parent = 0);
    18. protected:
    19. void paintEvent(QPaintEvent *event);
    20. void mousePressEvent(QMouseEvent *event);
    21. void mouseMoveEvent(QMouseEvent *event);
    22. void dragMoveEvent(QDragMoveEvent *event);
    23. private:
    24. void startDrag();
    25. QPoint startPos;
    26. bool insidePawn;
    27. //klasa pionka
    28. class Pawn {
    29. public:
    30. Pawn();
    31. Pawn(QColor &color, QRectF &rec);
    32. ~Pawn();
    33. const QColor &color() const { return color_; }
    34. const QRectF &rectF() const { return rectF_; }
    35. private:
    36. QColor color_;
    37. QRectF rectF_;
    38. QPixmap *dragPicture;
    39. };
    40. //
    41. Pawn *draggedPawn;
    42. QMap<int, Pawn> pawnCollection;
    43. };
    44. }
    45. #endif
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. PawnBox::Pawn::Pawn() {
    2. color_ = QColor(0,0,0);
    3. rectF_ = QRectF(5,5,20,20);
    4. dragPicture = new QPixmap(20,20);
    5. }
    6. PawnBox::Pawn::Pawn(QColor &color, QRectF &rec) {
    7. color_ = color;
    8. rectF_ = rec;
    9. dragPicture = new QPixmap(20,20);
    10. }
    11. PawnBox::Pawn::~Pawn() {
    12. delete dragPicture;
    13. }
    To copy to clipboard, switch view to plain text mode 

    SIGSEV

    Any hint?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Confusing SIGSEV

    Well, the code you posted cannot cause a crash.
    What about the draggedPawn pointer? Where and how do you use it?

    Regards

  3. #3
    Join Date
    May 2007
    Location
    Warsaw, Poland
    Posts
    52
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Confusing SIGSEV

    Actually when I get rid of "delete dragPicture;" in destructor, everything is fine, apart from the tiny memory leak.

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Confusing SIGSEV

    Do you have any other references to that pointer?
    Maybe after the class gets destroyed and the pixmap deleted someone still tries to use your pixmap.

    There should be no problem in simply deleting a pointer to a pixmap.

    Regards

  5. #5
    Join Date
    May 2007
    Location
    Warsaw, Poland
    Posts
    52
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Confusing SIGSEV

    I know what is wrong.
    I create Pawn objects on stack and then I put them inside QMap<int, Pawn> what evokes copy constructor. Therefore a pointer to a pixmap points still to the QPixmap of an old temporary object that is soon destroyed.

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Confusing SIGSEV

    OK then. That seems to be it.

Similar Threads

  1. Confusing in thread implementation
    By santosh.kumar in forum Qt Programming
    Replies: 0
    Last Post: 16th May 2007, 11:07

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.