[PyQt] QTreeView + sort + delete = crash

John F Sturtz john at sturtz.org
Mon May 6 02:52:13 BST 2019


Hi Kyle.  Thanks for the help.  Each time I post to this group, I learn a little more.

[1]
The x.py that you sent back passes the model tester when I run it as well.  I suspect the reason that the version I posted crashed was because I tried to instantiate the dialog widget (Dlg) from the tester function.  The tester function doesn't create a QApplication, so it was foolish of me to think it could create a widget there.

Your version just removed the Dlg() instantiation:

def test_model(qtmodeltester):
qtmodeltester.check(CategoryTreeModel())

which works (that is, the model passes the test).  This also works:

def test_model(qtmodeltester):
app = QtWidgets.QApplication(sys.argv)
dlg = Dlg()
qtmodeltester.check(dlg.model)

That is, it does not crash, and the model passes the test in this case also.

[2]
So, there doesn't seem to be anything obvious wrong with the model, at least not as far as the pytest-qt item model tester is concerned.  Which means I'm not much closer to knowing why the original code I posted crashes than I was before.  :-/

[3]
Regarding passing the view to the model:

The reason I did this is because, once an item in the tree is edited, I wanted to make it the current item (lines 224-226).  setCurrentIndex() is a view-level method, so I needed a reference to the view to invoke it (or thought I did).  I've bumped into this several times, and always 'solved' it this way (though I never did quite feel like it was the right thing to do).

What would be considered the 'right' way to handle this?  Should I be connecting a signal to the setCurrentIndex() slot and emitting that?

Thanks again!

/John
On 5/4/2019 11:55:16 PM, Kyle Altendorf <sda at fstab.net> wrote:
It's late so I won't promise it's testing properly... but the attached
.py runs the test and passes. I'd note that you shouldn't be passing
the view to the model. The intention is that the Qt defined interface
is all that is needed. For example, what happens when you have two
views for one model?

Cheers,
-kyle
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20190505/be72dc9d/attachment.html>


More information about the PyQt mailing list