Solved How I can delete QQueue delete items older than 5 seconds ?
-
Hi,
What is the best paroach to delete item in a QQueue (or in Qvector) older than 5 seconds . ? Something like time to Live for object..
Best
-
Hi
QQueue being a FIFO structure, its not really good for random access.
How many items will the container have ? -
@RahibeMeryem Why do you need this? What is the use case?
You will have to implement this by yourself. For example, each object could emit a signal after 5 seconds (using a QTimer) and the slot connected to it would then delete it. -
Use case:
I want to put plate / object names to the screen. If plate or objects is seen before such as in 5 or 10 second I want to pass dont want to print names.
-
@RahibeMeryem This is not a task for a container like QQueue.
-
Hi
You can use a map.
std::map<QString, QTime> UsedNames.
Then when you are about to display a Name,
check if its in map,
if yes, check timestamp , and decided if show again,
if not in list, simply add (with timestamp) and display on screen.
If in list and expired, replace in map with new timestamp for the wanted timeout.
something like that ;) -
-
@RahibeMeryem
Well it really depends how fast you need to draw new strings and check
but if any human must have time to read it, i think it will be plenty fast. -
-
@RahibeMeryem
Tha might very well be.
https://woboq.com/blog/qmap_qhash_benchmark.html
also often depends on how many items and/or if you insert a lot etc.