[PyQt] Qml: Instantiate a model derived from QAbstractListModel from qml.
Arjen Hiemstra
a.hiemstra at ultimaker.com
Thu Nov 27 09:14:29 GMT 2014
On 27 November 2014 at 02:36, B. B. <thebbzoo at gmail.com> wrote:
>
> Hey,
>
> I get a segmentation fault, when I use an instance of a ListModel in qml. The model is implemented in python, registered with the qml type system.
Hi,
I ran into the same thing yesterday. I was going to post about it but
now I see you already did.
>
> I get a segmentation fault.
> ------------------------------------------------------------------------
>
To expand on this, this is the backtrace of the segfault for me:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff180a20b in QQmlProperty::QQmlProperty(QQmlProperty const&)
() from /usr/lib/libQt5Qml.so.5
(gdb) bt
#0 0x00007ffff180a20b in QQmlProperty::QQmlProperty(QQmlProperty
const&) () from /usr/lib/libQt5Qml.so.5
#1 0x00007ffff1c47519 in QPyQmlObjectProxy::pySetTarget(QQmlProperty
const&) () from /usr/lib/python3.4/site-packages/PyQt5/QtQml.so
#2 0x00007ffff18dae73 in QQmlDelegateModel::setModel(QVariant const&)
() from /usr/lib/libQt5Qml.so.5
#3 0x00007ffff18f6b3b in ?? () from /usr/lib/libQt5Qml.so.5
#4 0x00007ffff18f6c72 in ?? () from /usr/lib/libQt5Qml.so.5
#5 0x00007ffff188affd in ?? () from /usr/lib/libQt5Qml.so.5
#6 0x00007ffff1813177 in
QQmlComponentPrivate::complete(QQmlEnginePrivate*,
QQmlComponentPrivate::ConstructionState*) () from
/usr/lib/libQt5Qml.so.5
#7 0x00007ffff1813237 in QQmlComponentPrivate::completeCreate() ()
from /usr/lib/libQt5Qml.so.5
#8 0x00007ffff1815340 in QQmlComponent::create(QQmlContext*) () from
/usr/lib/libQt5Qml.so.5
#9 0x00007ffff1883802 in
QQmlApplicationEnginePrivate::_q_finishLoad(QObject*) () from
/usr/lib/libQt5Qml.so.5
#10 0x00007ffff1883bb2 in QQmlApplicationEnginePrivate::startLoad(QUrl
const&, QByteArray const&, bool) () from /usr/lib/libQt5Qml.so.5
#11 0x00007ffff1883d90 in QQmlApplicationEngine::load(QString const&)
() from /usr/lib/libQt5Qml.so.5
#12 0x00007ffff1c21c4e in meth_QQmlApplicationEngine_load () from
/usr/lib/python3.4/site-packages/PyQt5/QtQml.so
#13 0x00007ffff7a5c609 in call_function (oparg=<optimized out>,
pp_stack=0x7fffffffd700) at Python/ceval.c:4234
#14 PyEval_EvalFrameEx (f=f at entry=0x7fffe007de08,
throwflag=throwflag at entry=0) at Python/ceval.c:2836
#15 0x00007ffff7a5c2b2 in fast_function (nk=<optimized out>,
na=<optimized out>, n=1, pp_stack=0x7fffffffd820, func=<optimized
out>) at Python/ceval.c:4331
#16 call_function (oparg=<optimized out>, pp_stack=0x7fffffffd820) at
Python/ceval.c:4259
#17 PyEval_EvalFrameEx (f=f at entry=0x7fffea4289d0,
throwflag=throwflag at entry=0) at Python/ceval.c:2836
#18 0x00007ffff7a5c2b2 in fast_function (nk=<optimized out>,
na=<optimized out>, n=1, pp_stack=0x7fffffffd940, func=<optimized
out>) at Python/ceval.c:4331
#19 call_function (oparg=<optimized out>, pp_stack=0x7fffffffd940) at
Python/ceval.c:4259
#20 PyEval_EvalFrameEx (f=0x7ffff6c1e438, throwflag=<optimized out>)
at Python/ceval.c:2836
#21 0x00007ffff7a5d859 in PyEval_EvalCodeEx (_co=0x18741b0,
_co at entry=0x7ffff6bb70c0, globals=0x0, locals=0x7ffff6c1e5b0,
args=0x0, argcount=-2139062144, argcount at entry=0,
kws=0x7fffe001aee0, kws at entry=0x0, kwcount=0, defs=0x0, defcount=0,
kwdefs=0x0, closure=0x0) at Python/ceval.c:3585
#22 0x00007ffff7a5d8fb in PyEval_EvalCode (co=co at entry=0x7ffff6bb70c0,
globals=globals at entry=0x7ffff6c1b3c8,
locals=locals at entry=0x7ffff6c1b3c8) at Python/ceval.c:773
#23 0x00007ffff7a79bb4 in run_mod (mod=mod at entry=0x6e1188,
filename=filename at entry=0x7ffff6b14b70,
globals=globals at entry=0x7ffff6c1b3c8,
locals=locals at entry=0x7ffff6c1b3c8,
flags=flags at entry=0x7fffffffdbc0, arena=arena at entry=0x68d550) at
Python/pythonrun.c:2180
#24 0x00007ffff7a7bde5 in PyRun_FileExFlags (fp=0x68d310,
filename_str=<optimized out>, start=<optimized out>,
globals=0x7ffff6c1b3c8, locals=0x7ffff6c1b3c8, closeit=1,
flags=0x7fffffffdbc0) at Python/pythonrun.c:2133
#25 0x00007ffff7a7cdb3 in PyRun_SimpleFileExFlags (fp=0x18741b0,
filename=0x7ffff6bdd168 "printer/printer.py", closeit=1,
flags=0x7ffff7722cc0 <main_arena>) at Python/pythonrun.c:1606
#26 0x00007ffff7a9301c in run_file (p_cf=<optimized out>,
filename=<optimized out>, fp=<optimized out>) at Modules/main.c:319
#27 Py_Main (argc=-156153120, argv=0x7ffff6bdd148) at Modules/main.c:751
#28 0x0000000000400af6 in main ()
>From my (admittedly limited) understanding of the code in QPyQmlObject
it seems the pySetTarget is meant for handling property value sources
but accidentally gets called here.
I also tried creating the model in a different part of the qml and
later assigning it to the view, which also crashes in QQmlProperty but
with a slightly different backtrace.
What does work is creating an object with slots that return an
instance of the model. It is not ideal but it is what I use at the
moment.
> I admit I do still not have the big golden overview over PyQt5 and Qml,
> but I think / hope :-) this should be perfectly legal....
I sure hope so as well. :) Not being able to create models from QML
would make the code quite a bit more ugly.
>
>
> I am using a fairly new daily snapshot : PyQt-gpl-5.4-snapshot-15b37c22d541/
I'm on PyQt 5.3.2 using Python 3.4.2
Cheers,
Arjen Hiemstra
--
IMAGINE IT >> MAKE IT
Meet us online at Twitter <http://twitter.com/ultimaker>, Facebook
<http://facebook.com/ultimaker>, Google+ <http://google.com/+Ultimaker>
www.ultimaker.com
More information about the PyQt
mailing list