The worlds best article on the subject:

https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/



Sent from my iPad

On Oct 10, 2018, at 2:11 PM, Jérôme Godbout 
<godbo...@amotus.ca<mailto:godbo...@amotus.ca>> wrote:

Make sure to check how QObject are related to a QThread. Each QObject belong to 
a single QThread and cannot be used into other thread. If you need the object 
into another thread to do processing or signal/slot, you will need the 
QObject::moveToThread() function on each object first.

You might want to check if the moveToThread() does affect children too (I'm not 
sure anymore), so you might only move the root parent or you might need to do 
your own function to move all children too. You also make a lot of parentless 
object into your code above, make sure this is what you want.

I did this with a secondary QQmlEngine that was executing some Qml declaration 
into is own other thread and then move the resulting object back to the main 
loop thread QQmlEngine. So it's doable but not too funny.

The GUI rendering can only work into the Main loop thread, take care if you do 
some rendering of the scene that will be rendered on screen. The offscreen 
rendering into buffer does't suffer from this limitation if I remember well. 
Note this is not Qt3D directly, but my guess here is that it's proabbly working 
the same way.

On Wed, 10 Oct 2018 at 08:01, Saif Suleiman 
<saifqahe...@gmail.com<mailto:saifqahe...@gmail.com>> wrote:
Currently I am trying to import a scene in my Qt3d application. The problem is, 
when creating an instance from QSceneLoader and set the sources QUrl then add 
it to an Entity, it freezes the application until it finishes the importing. I 
tried to put it in thread like :


void start()
{
    qDebug() << "Thread";

    QAspectEngine* pAs = new QAspectEngine();
    pAs->registerAspect(new QRenderAspect());

    QRenderSettings *renderSettings = new QRenderSettings();
    renderSettings->setActiveFrameGraph(new Qt3DExtras::QForwardRenderer());

   // Root entity
   Qt3DCore::QEntity *sceneRoot2 = new Qt3DCore::QEntity();
   sceneRoot2->addComponent(renderSettings);

   pAs->setRootEntity(QSharedPointer<QEntity>(sceneRoot2));

   Qt3DRender::QSceneLoader *sceneLoader = new Qt3DRender::QSceneLoader();
   SceneWalker sceneWalker(sceneLoader);
   QObject::connect(sceneLoader, &Qt3DRender::QSceneLoader::statusChanged, 
&sceneWalker, &SceneWalker::onStatusChanged);

   
sceneLoader->setSource(QUrl::fromLocalFile("C:/Users/USER/Downloads/TreeTest.obj"));
   sceneRoot2->addComponent(sceneLoader);

}


This fuction will run when the Qthread emit the started signal, but then i got 
this : QObject::setParent: Cannot set parent, new parent is in a different 
thread.

So i do not know how to import a scene in qt3d without freezing the app, can 
any one help please.

Thanks in advance.
_______________________________________________
Interest mailing list
Interest@qt-project.org<mailto:Interest@qt-project.org>
http://lists.qt-project.org/mailman/listinfo/interest


--


[https://docs.google.com/uc?export=download&id=1PzqBIgnmpnXWUhS9nkg1P3_-Ealbvl-X&revid=0B28h_MWkOCu2V2llWWs1M3gySUxQeVJFa3Q0Y3RxdkdtWjlzPQ]RAPPROCHEZ
 LA DISTANCE

Jérôme Godbout
Senior Software Developer

p: +1 (418) 800-1073 ext.:109
m: +1 (581) 777-0050

amotus.ca<http://www.amotus-solutions.com/>
statum-iot.com<http://statum-iot.com/>




_______________________________________________
Interest mailing list
Interest@qt-project.org<mailto:Interest@qt-project.org>
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to