[Solved]Exited with code -1073741819 when trying to create a new item by clicking on QGraphicsView.



  • I am catching mouse click event in a class that inherits from QGraphicsView, as follow:

    @

    class CustomView : public QGraphicsView
    {
    public:
    CustomView(QWidget*);
    void setSceneManager (SceneManager*);
    void draw();

    protected:
    SceneManager* sceneManager;

    //Handle events.
    void mousePressEvent(QMouseEvent *event);
    

    };
    @

    A class, SceneManager, can create new elements inside. The sort of elements that It can create is defined in an enum type, and the class method abailable to do that is:

    @
    void SceneManager::addItem(AvailableItems::ItemType t){
    DrawableItem* item;
    switch (t){
    case (AvailableItems::neuro):
    //Adding new neuron in view.
    item = new DrawableItem(this->scene);
    item->setFilePath(":/recursosimg/vecimg.svg");
    listItems.append(item);
    break;

    case (AvailableItems::connector):
        break; //TODO
    }
    

    }
    @
    This method is called from @ void mousePressEvent(QMouseEvent *event); @ in QGraphicsView subclass.
    Debugger shows a Segmentation fault at following line, when clicking on QGraphicsView subclass object:
    @
    item = new DrawableItem(this->scene);
    @
    Detailed message is:

    "The inferior stopped because it received a signal from the operating system. Signal Name: SIGSEGV Signal Meaning: Segmentation fault".
    Console shows " exited with code -1073741819" as well, when application is running from console, when clicking on the same area.

    I checked .dll libraries, i ve just one intallation of Qt5. I also tried with a new clean SO installation, and changing "{ }" blocks in switch statment:

    @
    case (AvailableItems::neuro):{
    }
    @

    With the same result. Any idea? Thank you


  • Moderators

    Make sure that this->scene pointer is valid.



  • Thank you for your fast reply.

    I added qDebug mark:

    @
    void SceneManager::addItem(AvailableItems::ItemType t){
    qDebug () << "Entering addItem";
    qDebug () << (!this->scene ? "Null pointer" : "Ok");
    DrawableItem* item;
    switch (t){
    case (AvailableItems::neuro):
    //Adding new neuron in view.
    item = new DrawableItem(this->scene);
    item->setFilePath(":/recursosimg/vecimg.svg");
    listItems.append(item);
    break;

    case (AvailableItems::connector):
        break; //TODO
    }
    

    }
    @
    With result:
    Entering addItem
    Ok
    And crash. So, I think its not null. It points to QGraphicsScene for the QGraphicsView.

    scene is declared as:

    @
    protected:
    QGraphicsScene scene;
    QList<Drawable
    > listItems;
    };
    @

    I ve noticed that there is an area where the applitaction never crashes if you click on. So, it works fine. Outside this area, it crashes.

    GUI shows all the area that i want, but it seems like only a sub-area is detecting click. Well, all the area detects click event, but outside this sub-area, it crashes at the second line, so app only shows "Entering addItem".

    @
    qDebug () << "Entering addItem"; //Crash here when click outside the sub-area.
    qDebug () << (!this->scene ? "Null pointer" : "Ok");
    //Continue correclty when click on sub-area.
    @

    This area is delimited with a visible border. Its not visible at design time with QtCreator. I ve promoted QGraphicsView with my inherit class CustomView.

    ----------------------- EDIT -----------------------------

    I think I doing something wrong. In my CustomView class, I ve declared it as follow:

    @
    class CustomView : public QGraphicsView
    {
    public:
    CustomView(QWidget*);
    @

    In constructor method, I'm passing the own QGraphicsView object, as:

    @
    CustomView view(w.getGraphicsView());
    @

    Where "w" is the MainWindow object, and getGraphicsView returns the QGraphicsView* object created by QtCreator that I want to manage. Now, I return the CustomView directly:

    @
    CustomView* view = w.getGraphicsView();
    @

    Sorry for wasting your time.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.