Qt thread connect to qml
-
I have a main program that create a QDeclarativeView for qml file, and also create a thread.
i want that the qml file will send signal to start the thread running. this is what i do:
@
QObject::connect(view.rootObject(),SIGNAL(startThread()),myThread,SLOT(start()));
@this is working, but this thread need to change a context property in the view when he is running.
when I do this the program end with memory error.@
void MyThread::run()
{
m_view->rootContext()->setContextProperty("newProperty", "blabla");
}
@I init the m_viewto be pointer to the view in the thread constructor, and I don't know why this failed.
any idea??
-
If it works, it's just by pure luck and happenstance. As Gerolf said, you can't access UI things inside of a thread.
By when they say you can't, it means that while there is nothing that keeps you from trying to access things from your thread, the underlying system is not designed to handle those accesses properly and the results are undefined. That means that in certain situations things could appear to work, but it's not expected, proper, or guaranteed to be repeatable.