Ahh. The reason I don't get an error is because of the break. As soon at the master root is found the loop is stopped and the rest of the function is carried on. I will take a look into where I have deleted the object by kept the reference and will post my results if all goes well (or not so well). If I have indeed deleted the item but left the reference could this be the function parameter referencing it and the actual list being reset?
On Thursday, 5 March 2015, Justin Israel <[email protected]> wrote: > This would be an unrelated problem to the previously mentioned design > issue. What it looks like to me is that you are a deleting recursedItem > (TreeWidgetItem) but leaving a reference to it in your container and then > calling text() again on it at a later recursion. Probably need to make sure > that whatever you are deleting is no longer in the dict. > > Also, I am not sure why this part doesn’t give you errors, but it seems > like you are changing a dictionary size while looping over it: > > # Iterate through the dictionary returned by the read model file functionfor > name in treeObjects: > # Get the root point and add it to the root of the tree > if name.startswith("rp_"): > ... > del treeObjects[name] # Remove the RP from the dictionary > > Normally I would expect that to be an error, since if you plan to add and > remove to a dict while looping over it, you should loop over a copy. > > On Fri, Mar 6, 2015 at 7:22 AM Benjam901 [email protected] > <http://mailto:[email protected]> wrote: > > Hello Justin, >> >> I am having some solid trouble with my recursive function trying to add >> QTreeWidgetItems to the tree hierarchy. The loop continues on and then gets >> to a certain point and this error pops up when I try to access a >> recursedItem in the list. >> >> RuntimeError: underlying C/C++ object has been deleted >> >> Could this have something to do with the design issues you were talking >> about? I have done some digging and read that python wrappers are left >> behind or I havent called my init function somewhere? >> >> Here is my function: >> >> def setupModelTree(self): >> import UnitManager.scripts.read_model_file as readModel >> treeObjects = readModel.testRead() >> addedToList = [] >> recurseRoots = [] >> recurseInnerRoots = [] >> recurseNo = -1 >> >> # Iterate through the dictionary returned by the read model >> file function >> for name in treeObjects: >> >> # Get the root point and add it to the root of the tree >> if name.startswith("rp_"): >> rootName = name >> rootItem = QtGui.QTreeWidgetItem([name]) >> recurseRoots.append(rootItem) >> self.modelTree.addTopLevelItem(rootItem) >> del treeObjects[name] # Remove the RP from the >> dictionary >> addedToList.append(name) >> break >> >> def recurseAddChildren(dict, iterList, recursiveItems): >> newlyAdded = [] >> recurseInnerRoots = [] >> >> # Iterating through through last added items layer >> for recursedItem in recursiveItems: >> addChildren = [] >> toDelete = [] >> """ @type recursedItem: >> QtGui.QTreeWidget.QTreeWidget """ >> if iterList[0] != rootName: >> for d in dict: >> if dict.get(d) == >> recursedItem.text(0): # Error line >> toDelete.append(d) >> >> addChildren.append(QtGui.QTreeWidgetItem([d])) >> >> self.deleteDictElements(dict, toDelete) >> >> for toBeAdded in addChildren: >> childItem = >> QtGui.QTreeWidgetItem(toBeAdded) >> recursedItem.addChild(childItem) >> >> >> newlyAdded.append(toBeAdded.text(0)) >> >> recurseInnerRoots.append(childItem) >> self.deleteDictElements(dict, >> toBeAdded.text(0)) >> >> if len(iterList) < 1: >> print "errored" >> break >> else: >> print "Adding first layer" >> for name in dict: >> parent = [item for item in >> iterList if item == dict.get(name)] >> >> # If the parent exists >> if parent: >> childToAdd = >> QtGui.QTreeWidgetItem([name]) >> >> >> recursedItem.addChild(childToAdd) >> newlyAdded.append(name) >> >> recurseInnerRoots.append(childToAdd) >> >> dict = self.deleteDictElements(dict, newlyAdded) >> >> # KEEP OUTSIDE MAIN LOOP >> if len(dict) > 0: >> recurseAddChildren(dict, >> newlyAdded,recurseInnerRoots) >> >> recurseAddChildren(treeObjects, addedToList, recurseRoots) >> print "Model panel set up" >> >> >> On Thursday, 5 March 2015 11:08:53 UTC+1, Justin Israel wrote: >> >>> Generally I would say it is a questionable design if you have child >>> classes that make assumptions about the members of the parent. It means >>> that your child class can only be used with that specific parent class that >>> will have the expected attributes. If your child class needs to trigger >>> behavior in the parent, a better design would be to have your child class >>> emit signals. This should give you a cleaner separation between the two >>> widgets. It then becomes the responsibility of your parent window to >>> connect to the signals of interest, and perform the required actions as it >>> is notified. >>> >>> >>> On Thu, Mar 5, 2015 at 10:27 PM Benjam901 <[email protected]> wrote: >>> >>>> Hello again Marcus, >>>> >>>> I was wondering why intellisense does not pick up on the internal >>>> variables and buttons etc. do I need to add another handle? >>>> >>>> Cheers, >>>> >>>> Ben >>>> >>>> On Thursday, 5 March 2015 09:29:23 UTC+1, Marcus Ottosson wrote: >>>> >>>>> self.modelTree = self.uiMainWindow.uiModelTree # This is where I get the >>>>> error >>>>> >>>>> self is referring to your instance of ModelWindow, but you store >>>>> uiMainWindow in the instance of MainWindowSetup. >>>>> >>>>> If you want to access that, you’ll need to pass a handle to it. It’s >>>>> typically done using a parent, but you aren’t including the parent in your >>>>> __init__ method. >>>>> >>>>> Try something like this. >>>>> >>>>> class MainWindowSetup(QtGui.QMainWindow): >>>>> def __init__(self): >>>>> QtGui.QMainWindow.__init__(self) >>>>> >>>>> self.uiMainWindow = Ui_MainWindow() >>>>> self.uiMainWindow.setupUi(self) >>>>> self.uiModelWindow = ModelWindow(self) >>>>> class ModelWindow(QtGui.QTreeWidget): >>>>> def __init__(self, parent): >>>>> print "!! Initialised model window" >>>>> QtGui.QTreeWidget.__init__(self, parent) >>>>> >>>>> self.modelTree = parent.uiMainWindow.uiModelTree # This is where >>>>> I get the error >>>>> >>>>> >>>>> >>>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "Python Programming for Autodesk Maya" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> To view this discussion on the web visit https://groups.google.com/d/ >>>> msgid/python_inside_maya/065722da-82df-4108-92d5- >>>> 6c76844d0696%40googlegroups.com >>>> <https://groups.google.com/d/msgid/python_inside_maya/065722da-82df-4108-92d5-6c76844d0696%40googlegroups.com?utm_medium=email&utm_source=footer> >>>> . >>>> For more options, visit https://groups.google.com/d/optout. >>>> >>> -- >> You received this message because you are subscribed to the Google Groups >> "Python Programming for Autodesk Maya" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] >> <javascript:_e(%7B%7D,'cvml','python_inside_maya%[email protected]');> >> . >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/bb4a178c-06a0-4f08-9aba-6e028573ebd0%40googlegroups.com >> <https://groups.google.com/d/msgid/python_inside_maya/bb4a178c-06a0-4f08-9aba-6e028573ebd0%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > You received this message because you are subscribed to a topic in the > Google Groups "Python Programming for Autodesk Maya" group. > To unsubscribe from this topic, visit > https://groups.google.com/d/topic/python_inside_maya/_aEnlsC_60Q/unsubscribe > . > To unsubscribe from this group and all its topics, send an email to > [email protected] > <javascript:_e(%7B%7D,'cvml','python_inside_maya%[email protected]');> > . > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2c_fHfxS4bhbdGwggRq8P5rfDzkSE9-%2Be8L%2BeRY2Phzg%40mail.gmail.com > <https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA2c_fHfxS4bhbdGwggRq8P5rfDzkSE9-%2Be8L%2BeRY2Phzg%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- Tel - +46 76245 92 90 (Sweden) LinkedIn: http://www.linkedin.com/pub/ben-hearn/50/a64/33b -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/CAM2ybkUFYPGS1kuTm0Dra4ddR%2B%2B%2B6g4pmGkn8AcmLyMgSvgT%3Dw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
