Results 1 to 3 of 3

Thread: Subclassing QGraphicsView crash the app

  1. #1
    Join Date
    Feb 2014
    Posts
    94
    Thanks
    5
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Subclassing QGraphicsView crash the app

    Hello all!

    I am trying to subclass QGraphicsView, but its crashing the app.

    How can I do that.

    fluxocaixagraphicsview.h
    Qt Code:
    1. #ifndef FLUXOCAIXAGRAPHICSVIEW_H
    2. #define FLUXOCAIXAGRAPHICSVIEW_H
    3.  
    4. #include <QGraphicsView>
    5. #include <QGraphicsScene>
    6. //#include <QGraphicsLineItem>
    7.  
    8. class fluxoCaixaGraphicsView : public QGraphicsView
    9. {
    10. public:
    11. explicit fluxoCaixaGraphicsView(QWidget *parent = 0);
    12. ~fluxoCaixaGraphicsView();
    13.  
    14. private:
    15. QGraphicsScene *cenario;
    16.  
    17. protected:
    18. void showEvent(QShowEvent *event);
    19. void resizeEvent(QResizeEvent *event);
    20. };
    21.  
    22. #endif // FLUXOCAIXAGRAPHICSVIEW_H
    To copy to clipboard, switch view to plain text mode 

    fluxocaixagraphicsview.cpp
    Qt Code:
    1. #include "fluxocaixagraphicsview.h"
    2.  
    3. fluxoCaixaGraphicsView::fluxoCaixaGraphicsView(QWidget *parent) :
    4. QGraphicsView(parent)
    5. {
    6. QGraphicsScene *cenario = new QGraphicsScene(this);
    7. }
    8.  
    9. fluxoCaixaGraphicsView::~fluxoCaixaGraphicsView()
    10. {
    11.  
    12. }
    13.  
    14. void fluxoCaixaGraphicsView::showEvent(QShowEvent *event)
    15. {
    16.  
    17. }
    18.  
    19. void fluxoCaixaGraphicsView::resizeEvent(QResizeEvent *event)
    20. {
    21.  
    22. }
    To copy to clipboard, switch view to plain text mode 

    calling it
    Qt Code:
    1. QWidget *MainWindow::criaEstruturaNovoIvestimento()
    2. {
    3. //code here
    4.  
    5. fluxoCaixaGraphicsView *graphicsViewFluxoCaixa = new fluxoCaixaGraphicsView(boxInvestimento3);
    6.  
    7. //code here
    8. }
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Subclassing QGraphicsView crash the app

    Qt Code:
    1. fluxoCaixaGraphicsView::fluxoCaixaGraphicsView(QWidget *parent) :
    2. QGraphicsView(parent)
    3. {
    4. QGraphicsScene *cenario = new QGraphicsScene(this);
    5. }
    To copy to clipboard, switch view to plain text mode 
    you just declared a local variable named "cenario", it is not the same as your "cenario" in the header file
    change this to
    Qt Code:
    1. fluxoCaixaGraphicsView::fluxoCaixaGraphicsView(QWidget *parent) :
    2. QGraphicsView(parent)
    3. {
    4. this->cenario = new QGraphicsScene(this);
    5. }
    To copy to clipboard, switch view to plain text mode 
    btw. you should call base class implementation of the reimplemented event handlers.

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Subclassing QGraphicsView crash the app

    Also need to insert the Q_OBJECT macro in the fluxoCaixaGraphicsView class definition:

    Qt Code:
    1. class fluxoCaixaGraphicsView : public QGraphicsView
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. explicit fluxoCaixaGraphicsView(QWidget *parent = 0);
    7. ~fluxoCaixaGraphicsView();
    8.  
    9. // ...
    10. };
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QGraphicsView crash... how to debug ?
    By pl01 in forum Newbie
    Replies: 3
    Last Post: 24th February 2011, 09:51
  2. Subclassing QNetworkReply
    By piotr.dobrogost in forum Qt Programming
    Replies: 6
    Last Post: 19th December 2010, 09:42
  3. Crash gracefully? No crash!
    By lni in forum Qt Programming
    Replies: 0
    Last Post: 7th July 2010, 04:59
  4. Subclassing QGraphicsView
    By sincnarf in forum Qt Programming
    Replies: 11
    Last Post: 27th August 2007, 20:36
  5. Subclassing
    By joseph in forum Newbie
    Replies: 1
    Last Post: 25th February 2006, 15:06

Tags for this Thread

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.