Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-71211

Make QTimer::remainingTime() work outside of its thread

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • None
    • Core: Event loop
    • None

    Description

      Perhaps I'm abusing the API slightly, but I have a use case for querying QTimer::remainingTime() from another thread, which currently doesn't work because the implementation doesn't pass thread() into QAbstractEventDispatcher::instance():

      int QTimer::remainingTime() const
      {
          if (id != INV_TIMER) {
              return QAbstractEventDispatcher::instance()->remainingTime(id);
          }
      
          return -1;
      } 

      I'm currently doing a workaround like to get what I need:

      if (my_timer.isActive())
          return QAbstractEventDispatcher::instance(my_timer.thread())->remainingTime(my_timer_.timerId());
      else
          return -1;

      and I understand there are race-conditions here when called outside of the timer thread but as long as the user knows what they are doing and are ready to handle the -1 cases I think it would be useful for QTimer::remainingTime() to do this for us?

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            derekchow Derek Chow
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes