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



  • 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


  • Lifetime Qt Champion

    Hi,

    Can you share the code you use that triggers that ?



  • @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?


  • Moderators

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


  • Qt Champions 2017

    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.



  • @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!


Log in to reply
 

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