Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How I can delete QQueue delete items older than 5 seconds ?
Qt 6.11 is out! See what's new in the release blog

How I can delete QQueue delete items older than 5 seconds ?

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 1.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    RahibeMeryem
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      QQueue being a FIFO structure, its not really good for random access.
      How many items will the container have ?

      1 Reply Last reply
      3
      • R RahibeMeryem

        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

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @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.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        4
        • R Offline
          R Offline
          RahibeMeryem
          wrote on last edited by
          #4

          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.

          jsulmJ 1 Reply Last reply
          0
          • R RahibeMeryem

            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.

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @RahibeMeryem This is not a task for a container like QQueue.

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by mrjj
              #6

              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 ;)

              1 Reply Last reply
              5
              • R Offline
                R Offline
                RahibeMeryem
                wrote on last edited by
                #7

                @jsulm and @mrjj thanks. I will use map and assume its fast enough to check 100 items :)

                mrjjM 1 Reply Last reply
                0
                • R RahibeMeryem

                  @jsulm and @mrjj thanks. I will use map and assume its fast enough to check 100 items :)

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @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.

                  1 Reply Last reply
                  3
                  • R Offline
                    R Offline
                    RahibeMeryem
                    wrote on last edited by
                    #9

                    @mrjj

                    I used QHash it looks faster look up than map.

                    Best

                    mrjjM 1 Reply Last reply
                    1
                    • R RahibeMeryem

                      @mrjj

                      I used QHash it looks faster look up than map.

                      Best

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @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.

                      1 Reply Last reply
                      3

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved