# Publisher - Custom UI - Internal C++ object (PySide2.QtWidgets.QListWidgetItem) already deleted

**URL:** <https://community.shotgridsoftware.com/t/publisher-custom-ui-internal-c-object-pyside2-qtwidgets-qlistwidgetitem-already-deleted/13508>\
**Category:** Pipeline Integrations\
**Created:** [September 21, 2021, 1:24pm UTC](https://community.shotgridsoftware.com/t/publisher-custom-ui-internal-c-object-pyside2-qtwidgets-qlistwidgetitem-already-deleted/13508 "2021-09-21T13:24:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Davidvh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Davidvh](https://community.shotgridsoftware.com/u/Davidvh)\
**Post date:** [September 21, 2021, 1:24pm UTC](https://community.shotgridsoftware.com/t/publisher-custom-ui-internal-c-object-pyside2-qtwidgets-qlistwidgetitem-already-deleted/13508/1 "2021-09-21T13:24:24Z")

</div>

Hello community,

So I’m extending the Publisher with some extra UI elements for some extra functionality. Bare with me, I’m not an expert in Qt.

Now, I’ve added a QListWidget which holds soms items. But I’m having some issues with the getter and setter.  
So first I populate the list with a function that creates the items. Then I use the following code for the getting and setting. Obviously the setter code is not done yet. So mainly debugging and printing stuff there.

```
@property
def worker_selection(self):
    checked_items = []
    for index in range(self.workers_list.count()):
        if self.workers_list.item(index).checkState() == QtCore.Qt.Checked:
            checked_items.append(self.workers_list.item(index))

    return checked_items

@worker_selection.setter
def worker_selection(self, value):
    for v in value:
        print v
        print v.isSelected()

```

Now when I select an item in the UI, go to another “layer” in the Shotgun view on the left and go back to the list again, I’m getting:

Internal C++ object (PySide2.QtWidgets.QListWidgetItem) already deleted.

So it looks like at the moment I want to do something with the Object in the setter, python deletes it.

Can anybody shine some light on this?

Cheers,

David

---

<div class="post-metadata">

**Author:** ![vtrvtr](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/vtrvtr/32/892_2.png) [@vtrvtr](https://community.shotgridsoftware.com/u/vtrvtr)\
**Post date:** [September 22, 2021, 8:26pm UTC](https://community.shotgridsoftware.com/t/publisher-custom-ui-internal-c-object-pyside2-qtwidgets-qlistwidgetitem-already-deleted/13508/2 "2021-09-22T20:26:48Z")

</div>

Hello, David. The “correct” way to setup custom widgets is to only interact with them using the [predefined functions](https://developer.shotgridsoftware.com/tk-multi-publish2/customizing.html#tk_multi_publish2.base_hooks.PublishPlugin.create_settings_widget) for `create_*`, `get_*`, and `set_*`. Here’s [an example](https://github.com/shotgunsoftware/tk-multi-publish2/blob/fdd309df1f892c5223be9da2c58b0b13e3bffa26/tests/fixtures/config/hooks/vitor_test.py). Doing so will guarantee you only access the widgets when they are in scope, avoiding the issue you’re seeing.

Cheers,

---

<div class="post-metadata">

**Author:** ![Davidvh](https://avatars.discourse-cdn.com/v4/letter/d/8797f3/32.png) [@Davidvh](https://community.shotgridsoftware.com/u/Davidvh)\
**Post date:** [September 23, 2021, 7:39am UTC](https://community.shotgridsoftware.com/t/publisher-custom-ui-internal-c-object-pyside2-qtwidgets-qlistwidgetitem-already-deleted/13508/3 "2021-09-23T07:39:52Z")

</div>

Cheers mate!

That pointed me in the right direction.  
The answer was right in front of me the whole time.  
I tried to work with the objects themselfs, but all I had to do was passing down a list to the setter.

I stared at my screen for too long I guess 😉

Thanks!
