Help with QTimer scope
-
@Christianvs What is ROS_INFO_STREAM?
Can you try qDebug() instead to verify the slot is called?The whole project is connected through ROS as it controls an AC motor. To be honest i'm not sure if qDebug works in my current setup.
None the less i got the timer to say it's active by running isActive() after i start the timer (what a stupid mistake!)
But that actually solves part of my problem as i now know the timer is actually active!
But it still does not execute the timerTest() function!
-
The whole project is connected through ROS as it controls an AC motor. To be honest i'm not sure if qDebug works in my current setup.
None the less i got the timer to say it's active by running isActive() after i start the timer (what a stupid mistake!)
But that actually solves part of my problem as i now know the timer is actually active!
But it still does not execute the timerTest() function!
@Christianvs said in Help with QTimer scope:
qDebug works in my current setup
std::cout should work.
And you can place a breakpoint inside the slot and start through debugger. -
Could the problem be that my weightChanger object somehow needs to be initialized in another way? By using new ?
Above is where i actually initialize the object and it is within this object the QTimer is stored
-
Could the problem be that my weightChanger object somehow needs to be initialized in another way? By using new ?
Above is where i actually initialize the object and it is within this object the QTimer is stored
@Christianvs said in Help with QTimer scope:
Could the problem be that my weightChanger object somehow needs to be initialized in another way? By using new ?
Yes! When this function ends, it will be destroyed (object goes out of scope).
-
@Christianvs said in Help with QTimer scope:
Could the problem be that my weightChanger object somehow needs to be initialized in another way? By using new ?
Yes! When this function ends, it will be destroyed (object goes out of scope).
@sierdzio @Christianvs You can see this type of error very often here :-)
-
Yay! Now that i create it on the heap using new the timers work without any problems!
Thanks for the help all of you! :)
-
Just make sure it is cleaned up properly afterwards (either assign
this
as parent or calldelete
on it when you don't need it anymore). -
@Christianvs if your issue is solved, please don't forget to mark your post as such. Thanks.
-
Just make sure it is cleaned up properly afterwards (either assign
this
as parent or calldelete
on it when you don't need it anymore).@sierdzio
Is there any downside to just calling this as parent?@Pablo-J-Rogina
I actually cannot find where to mark it as solved
EDIT: Done! :) -
@sierdzio
Is there any downside to just calling this as parent?@Pablo-J-Rogina
I actually cannot find where to mark it as solved
EDIT: Done! :)@Christianvs said in Help with QTimer scope:
Is there any downside to just calling this as parent?
No. The other solution is worse, because it is easy to forget about calling
delete
. If you use Qt's parent-child system, then Qt will automatically delete objects when their parent is deleted.There is a possibility that it is not the behaviour you want, but that is not something we can determine from the code above.
Other options for managing object life:
- QSharedPointer
- stl pointers