Maya Problem. Internal C++ object already deleted. PyQt vs PySide

Hello guys. I’ve got following problem.

Here is a little code that creates a simple Maya UI and then inserts a QTableView in it.
And its working very well and everything is fine.

import maya.cmds as m
import maya.OpenMayaUI as omui
import sip
from PyQt4 import QtCore
from PyQt4 import QtGui

UI_WIN_NAME = 'test_pyqt_embedding_win'


class TestUI(object):

    def __init__(self):
        if m.window(UI_WIN_NAME, exists=True):
            m.deleteUI(UI_WIN_NAME, window=True)
        self.window = m.window(UI_WIN_NAME)

        self.uiLAY_mainRow = m.columnLayout(adjustableColumn=True)
        self.uiLAY_attachFrame = m.frameLayout(marginHeight=2, marginWidth=2, borderVisible=True, labelVisible=True)
        self.uiBTN_test = m.button()

        self.uiQTLAY_attachFrame = sip.wrapinstance(long(omui.MQtUtil.findLayout(self.uiLAY_attachFrame)), QtCore.QObject)
        self.uiQTLAY_attachLayout = self.uiQTLAY_attachFrame.children()[-1].layout()

        self.uiQTTBL_test = QtGui.QTableView()
        self.uiQTLAY_attachLayout.addWidget(self.uiQTTBL_test)

        m.showWindow(self.window)


def run():
    TestUI()

But if i try to do this stuff in PySide (only 4 lines has been changed) it fails with an error “# Error: RuntimeError: file … estEmbeddingPySide.py line 25: Internal C++ object (PySide.QtGui.QVBoxLayout) already deleted. #”

import maya.cmds as m
import maya.OpenMayaUI as omui
import shiboken
from PySide import QtCore
from PySide import QtGui

UI_WIN_NAME = 'test_pyside_embedding_win'


class TestUI(object):

    def __init__(self):
        if m.window(UI_WIN_NAME, exists=True):
            m.deleteUI(UI_WIN_NAME, window=True)
        self.window = m.window(UI_WIN_NAME)

        self.uiLAY_mainRow = m.columnLayout(adjustableColumn=True)
        self.uiLAY_attachFrame = m.frameLayout(marginHeight=2, marginWidth=2, borderVisible=True, labelVisible=True)
        self.uiBTN_test = m.button()

        self.uiQTLAY_attachFrame = shiboken.wrapInstance(long(omui.MQtUtil.findLayout(self.uiLAY_attachFrame)), QtCore.QObject)
        self.uiQTLAY_attachLayout = self.uiQTLAY_attachFrame.children()[-1].layout()

        self.uiQTTBL_test = QtGui.QTableView()
        self.uiQTLAY_attachLayout.addWidget(self.uiQTTBL_test)

        m.showWindow(self.window)


def run():
    TestUI()

Any idea how can i fix it? Or may be i’m doing something wrong?

im assuming its due to the qt manager cleaning up widgets. just curious as to why you’re going this route. Why not make the ui in qt to begin with and just parent it to the maya window? Mixing the mel created UI with pyside/qt gets tricky and is pretty messy.

I’ve made a tool (let’s call it Outliner Plus). It is a standard Maya Outliner with some useful buttons, tools and other stuff including search.
I prefer to construct my own window with Maya UI and insert there an Outliner Panel. What i need is QTableView for some purposes.
This approach is not messy and working very well. Only several lines to embed Qt control and everything working fine.
I’ve got a thread about embedding problem and Temujin help me a lot.

Anyway… This tool was written about 2 years ago using PyQt and it is working fine. What I’ve decided lately is try to migrate this tool to PySide
to simplify tool distribution (no need to supply PyQt for Maya for specific version). And this problem was arose.

The question is about difference between PyQt and PySide when wrapping an instance.
Completely the same code and PyQt doing well, but PySide fails.
I’m almost sure that it can be fixed somehow.

import maya.cmds as m
import maya.OpenMayaUI as omui
import shiboken
from PySide import QtCore
from PySide import QtGui

UI_WIN_NAME = 'test_pyside_embedding_win'


class TestUI(object):

    def __init__(self):
        if m.window(UI_WIN_NAME, exists=True):
            m.deleteUI(UI_WIN_NAME, window=True)
        self.window = m.window(UI_WIN_NAME)

        self.uiLAY_mainRow = m.columnLayout(adjustableColumn=True)
        self.uiLAY_attachFrame = m.frameLayout(marginHeight=2, marginWidth=2, borderVisible=True, labelVisible=True)
        self.uiBTN_test = m.button()

        self.uiQTLAY_attachFrame = shiboken.wrapInstance(long(omui.MQtUtil.findLayout(self.uiLAY_attachFrame)), QtCore.QObject)
        self.uiQTLAY_attachLayout = self.uiQTLAY_attachFrame.children()[-1].children()[0]

        self.uiQTTBL_test = QtGui.QTableView()
        self.uiQTLAY_attachLayout.addWidget(self.uiQTTBL_test)

        m.showWindow(self.window)


def run():
    TestUI()

Not sure why the the layout() method’s return is getting cleaned up like that, but if you get your layout from the children() array instead it seems to work.

[QUOTE=R.White;24957]Not sure why the the layout() method’s return is getting cleaned up like that, but if you get your layout from the children() array instead it seems to work.[/QUOTE]

Thanks !!! That’s what i’ve looking for. It works.