Hi Tim,

On 18/03/2011, at 1:50 AM, ext Tim O'Callaghan wrote:
> 
> I've been playing with this example, to try adding a thread that 
> randomly adds new items to an Abstract model, using a separate thread.
> 
> It seems the abstractmodel+QML cannot cope with updating. I'm hoping its 
> something wrong with the model implementation, i guess it needs to send 
> a dataChanged signal or something? The error it generates when 
> attempting to add the second new item is:
> 
> QObject::connect: Cannot queue arguments of type 'QModelIndex'
> (Make sure 'QModelIndex' is registered using qRegisterMetaType().)
> 
> How do i fix this?
> 
> The changed main.cpp is attached, the rest of the source for the example 
> is here:
> http://qt.gitorious.org/qt/qt/trees/4.7/examples/declarative/modelviews/abstractitemmodel
> 

The error arises because the model is being modified from your worker thread 
rather than the main thread.

Qt model classes are not thread safe and should not be modified from separate 
threads. To implement your case, you can simply send a message from your worker 
thread to your main thread (e.g. using signals) when the model should be 
updated, so that addAnimal() is called from within the main thread rather than 
the worker thread. 

http://developer.qt.nokia.com/wiki/Threads_Events_QObjects has some useful 
information about threading and using signals and slots between threads.


regards,

Bea



_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

Reply via email to