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 to timeouts a lot of objects

How to timeouts a lot of objects

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.3k 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.
  • _ Offline
    _ Offline
    _Mark_
    wrote on last edited by
    #1

    Hello,
    I receive a lot of events from a class. This is the slot called:

    @
    void caught(int idx);
    @

    When executed it highlights the row number 'idx' on a QTableView.
    I want to clear each highlight after, say, 250 ms.
    It would be EXTREMELY easy if I can write:

    @
    void caught(int idx)
    {
    model->highlightRow(idx);
    QTimer::singleShot(250, model, SLOT(clearHighlightRow(idx)));
    }
    @

    but for some reasons you cannot call a SLOT with parameters :-(

    What is the recommended way to achieve the same behavior?

    1 Reply Last reply
    0
    • _ Offline
      _ Offline
      _Mark_
      wrote on last edited by
      #2

      I found an ugly workaround. In the caught SLOT I enqueue idx and call the singleShot method.
      In its own SLOT I dequeue the idx and clear the highlight.

      It works, but I don't like it at all.

      1 Reply Last reply
      0
      • C Offline
        C Offline
        ckakman
        wrote on last edited by
        #3

        If you are using Qt 5.4 and a compiler that supports C++11, you can call QTimer::singleShot() with a lambda function.

        1 Reply Last reply
        0
        • _ Offline
          _ Offline
          _Mark_
          wrote on last edited by
          #4

          Unfortunately I'm still with Qt5.3.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            Works in all of Qt 5.x as long as you have a compiler that support C++/11 or up.

            So, simply write:
            @
            void caught(int idx)
            {
            model->highlightRow(idx);
            QTimer::singleShot(250, model, idx {model->clearHighlight(idx);});
            }
            @

            One thing to take care off: this will cause a crash if model is destructed while there is still a timer running. You can solve that using a QPointer<MyModel> instead of passing a plain pointer to the closure.

            1 Reply Last reply
            0

            • Login

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