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. Delete QGraphicsItem-Object in mainwindow.cpp causes program crash at "std::__atomic_base<int>::load" in a file "atomic_base.h"

Delete QGraphicsItem-Object in mainwindow.cpp causes program crash at "std::__atomic_base<int>::load" in a file "atomic_base.h"

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 1.9k Views 2 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.
  • NiagarerN Offline
    NiagarerN Offline
    Niagarer
    wrote on last edited by Niagarer
    #1

    Hi!
    I try to delete an object of a QGraphicsItem derived class in my mainWindow (after I clicked on a delete button).
    The program crashes. I tried in debug mode and after my slot function (which gets executed, when I click on the delete button)

    void MainWindow::on_delete_pushButton_clicked()
    {
        if(selectedItemSet){ //bool attribute
            allItems.removeOne(selectedItem); //allItems = QVector<item*>
            delete selectedItem;
            selectedItemSet = false;
            setUpItems();
            update();
            qDebug() << "test";
        }
    }
    

    ran completely through (I added a breakpoint at the last line in the function and I had to continue it), the program stops and gives me this line in a file "atomic_base.h" (not a file by me, by the framework itself):

    	return __atomic_load_n(&_M_i, __m);
    

    Is this just a little classic mistake, or a bigger thing?
    Thanks for answers

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Can you share the code you use that triggers that ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      NiagarerN 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        Can you share the code you use that triggers that ?

        NiagarerN Offline
        NiagarerN Offline
        Niagarer
        wrote on last edited by Niagarer
        #3

        @SGaist
        I did...?
        The code I have shown in the question is actually everything. I have a button in my window named delete_pushButton and once I click on it, it should remove an item and delete it (I stored it in selectedItem), and this is the slot that gets executed then. I don't do anything else when I click on the delete_pushButton. And this std::__atomic_base<int>::load is not by me, it is a framework file and the debugger stops there.
        What else code do you need?

        jsulmJ 1 Reply Last reply
        0
        • NiagarerN Niagarer

          @SGaist
          I did...?
          The code I have shown in the question is actually everything. I have a button in my window named delete_pushButton and once I click on it, it should remove an item and delete it (I stored it in selectedItem), and this is the slot that gets executed then. I don't do anything else when I click on the delete_pushButton. And this std::__atomic_base<int>::load is not by me, it is a framework file and the debugger stops there.
          What else code do you need?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Niagarer But you said that your app crashes after the slot was executed, so not in the code you shown.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Also
            You are using
            QGraphicsScene::removeItem(QGraphicsItem * item);

            to remove them?

            If you just put in list while adding to scene and then later ONLY delete via list, you
            will have issue with the scene as it still owns them.

            NiagarerN 1 Reply Last reply
            2
            • mrjjM mrjj

              Also
              You are using
              QGraphicsScene::removeItem(QGraphicsItem * item);

              to remove them?

              If you just put in list while adding to scene and then later ONLY delete via list, you
              will have issue with the scene as it still owns them.

              NiagarerN Offline
              NiagarerN Offline
              Niagarer
              wrote on last edited by
              #6

              @mrjj
              Ok, thanks.
              Yes I did not call removeItem.
              I was focused on my vectors, because I only set up the QGraphicsView with the vectors of the items, but yep, I forgot to remove them manually.
              I was just a bit confused cus of the weird debug error position (atomic_base.h ...).
              Thanks for your help!

              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