Results 1 to 8 of 8

Thread: Timer update as I add objects

  1. #1
    Join Date
    Jun 2020
    Posts
    4
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Timer update as I add objects

    hello Everyone I am new to Qt, my project consists of reading data from csv file to make skeleton animation with spheres and for that I used Qtimer to add spheres at each timeout for the next line of data, for now it works but it saves the old spheres that I added at the previous timeout, I tried creating new QEntity but it didn't work, please help guys thank you in advance

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Timer update as I add objects

    Quote Originally Posted by Winnssench View Post
    hello Everyone I am new to Qt, my project consists of reading data from csv file to make skeleton animation with spheres and for that I used Qtimer to add spheres at each timeout for the next line of data, for now it works but it saves the old spheres that I added at the previous timeout, I tried creating new QEntity but it didn't work, please help guys thank you in advance
    You are going to have to show at least a pseudo-code description of what you are doing... but a compilable example of what you are doing would be better.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

  3. #3
    Join Date
    Jun 2020
    Posts
    4
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Timer update as I add objects

    thank you for your reply,
    here is the GitHub repo for my project
    https://github.com/Winssench/SkReader.git
    here is the function I call in the timer recursively
    Qt Code:
    1. Qt3DCore::QEntity * MyTimer::myslot(QVector<SkeletonBuilder*> _CurrentBuilder)
    2. {
    3. SkeletonBuilder* Currento = _CurrentBuilder.first();
    4.  
    5. Qt3DCore::QEntity* test = new Qt3DCore::QEntity();
    6. Currento->paintSkeleton(test);
    7. test->setParent(_root);
    8. CurrentBuilder.removeFirst();
    9. return test;
    10. }
    To copy to clipboard, switch view to plain text mode 
    the paintSkeleton fonction in the SkeletonBuilder class
    Qt Code:
    1. Qt3DCore::QEntity * SkeletonBuilder::paintSkeleton( Qt3DCore::QEntity *ls)
    2. {
    3.  
    4. QVector<Joint> skeletonBase = this->build();
    5. Qt3DCore::QEntity *global= new Qt3DCore::QEntity(ls);
    6.  
    7. for(int i=0 ; i <skeletonBase.size() ; i++)
    8. {
    9. Qt3DCore::QEntity *sphereEntity = new Qt3DCore::QEntity(ls);
    10. Qt3DExtras::QSphereMesh *sphereMesh = new Qt3DExtras::QSphereMesh;
    11. sphereMesh->setRadius(0.3);
    12. sphereMesh->setGenerateTangents(true);
    13.  
    14. Qt3DCore::QTransform *sphereTransform = new Qt3DCore::QTransform;
    15. sphereTransform->setScale(0.98f);
    16.  
    17. //get the coordinates
    18. Joint Currento = skeletonBase.at(i);
    19. QString jointName = Currento.getName();
    20. qDebug() <<Currento.getCoordinates() << Currento.getName()<< Qt::endl;
    21. sphereTransform->setTranslation(Currento.getCoordinates()*10);
    22. sphereTransform->setRotation(Currento.getQuaternion());
    23.  
    24. auto *materialSphere = new Qt3DExtras::QPhongMaterial(sphereMesh);
    25. sphereEntity->addComponent(sphereMesh);
    26. sphereEntity->addComponent(sphereTransform);
    27. sphereEntity->addComponent(materialSphere);
    28.  
    29. }
    30. return global;
    31. }
    To copy to clipboard, switch view to plain text mode 
    and the main
    Qt Code:
    1. int main(int argc, char* argv[])
    2. {
    3. QGuiApplication app(argc, argv);
    4.  
    5. Qt3DCore::QEntity* rootEntity = new Qt3DCore::QEntity ;
    6.  
    7. Qt3DExtras::Qt3DWindow* view = new Qt3DExtras::Qt3DWindow;;
    8. QVector<QVector<Joint>> skeletonData= createScene();
    9. QVector<SkeletonBuilder*> test;
    10.  
    11.  
    12. for(int i = 0 ; i< 218; i++)
    13. {
    14. Qt3DCore::QEntity *tamp = new Qt3DCore::QEntity;
    15. SkeletonBuilder* sb = new SkeletonBuilder(skeletonData,i,tamp);
    16. test.append(sb);
    17. }
    18.  
    19. MyTimer *myTimer = new MyTimer( new Qt3DCore::QEntity,test);
    20.  
    21. Qt3DRender::QCamera *camera = view->camera();
    22. camera->lens()->setPerspectiveProjection(45.0f, 16.0f/9.0f, 0.1f, 1000.0f);
    23. camera->setPosition(QVector3D(0, 0, 40.0f));
    24. camera->setViewCenter(QVector3D(0, 0, 0));
    25.  
    26. // For camera controls
    27. Qt3DExtras::QOrbitCameraController *camController = new Qt3DExtras::QOrbitCameraController(myTimer->getRoot());
    28. camController->setLinearSpeed( 50.0f );
    29. camController->setLookSpeed( 180.0f );
    30. camController->setCamera(camera);
    31.  
    32.  
    33. view->setRootEntity(myTimer->getRoot());
    34.  
    35. //view.hide();
    36. view->show();
    37.  
    38. return app.exec();
    39. }
    To copy to clipboard, switch view to plain text mode 
    hope this show bit the picture
    Screenshot 2020-06-12 at 06.34.14.jpg
    Last edited by Winnssench; 15th June 2020 at 14:42.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Timer update as I add objects

    CurrentBuilder.removeFirst();
    Is this your real code? The argument you pass in to MyTimer:: mySlot() is named "_CurrentBuilder", not "CurrentBuilder", so you are not modifying the same QVector as the one you passed as an argument.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Jun 2020
    Posts
    4
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Timer update as I add objects

    Im sorry about the quality of the code, I was changing bit values its true it was first as you described but the animation doesn't start, it does only when I use the private CurrentBuilder but it saves the older spheres created
    in the constructor I assign the _CurrentBuilder passed in the arguments to the private attribute of the class

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Timer update as I add objects

    You are also passing in the _CurrentBuilder QVector -by value-, which means it is making a copy of the argument you call it with. So the QVector you are modifying is the copy, not the original. If you want to avoid this, call it with QVector<> & _CurrentBuilder.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Jun 2020
    Posts
    4
    Qt products
    Qt5
    Platforms
    MacOS X

    Default Re: Timer update as I add objects

    I fixed to use the reference instead of the copy but the problem persists, I think it is the way I show the spheres that causes the problem, each time it passes the QEntity(with all the spheres included) to the rootEntity
    it draws them and then it adds another one while timeout is happening, but this logically would save the older spheres and this is what happens, if anyone has an idea how I can remove old QEntities from the rootEntity probably that would solve the issue

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Timer update as I add objects

    if anyone has an idea how I can remove old QEntities from the rootEntity probably that would solve the issue
    I think you can just call deleteLater() on the entity pointer. From what I can read of the QNode / QEntity documentation, there are no explicit methods to remove child nodes, but since QNode inherits from QObject, it has the same behavior - simply delete the child and the QObject parent - child relationship takes care of the cleanup. Use deleteLater(), not delete() so that QObject can perform a proper cleanup (and so your program doesn't crash because the pointer has been deleted before Qt has cleaned up references to it).

    If you are having a problem with identifying the spheres you want to delete, then you probably need to keep an extra data structure that stores them when you create them.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 6
    Last Post: 4th September 2014, 10:06
  2. Threads, Timer and Update a Field
    By lima_will in forum Newbie
    Replies: 2
    Last Post: 2nd October 2013, 09:05
  3. single timer for multiple objects
    By prabhatjha in forum Newbie
    Replies: 8
    Last Post: 30th August 2013, 09:54
  4. timer problem(timer does not work)
    By masuk in forum Newbie
    Replies: 6
    Last Post: 14th February 2011, 06:00
  5. Replies: 7
    Last Post: 18th July 2006, 22:33

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.