Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved]Exited with code -1073741819 when trying to create a new item by clicking on QGraphicsView.

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rhadel
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Make sure that this->scene pointer is valid.

      (Z(:^

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Rhadel
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved