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. Qtimer object blocking an application.
Forum Updated to NodeBB v4.3 + New Features

Qtimer object blocking an application.

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 6.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
    RSousa
    wrote on last edited by
    #1

    Hello,

    Im using a Qtimer object in order to create a repetitive event in a application. However this object is always running and blocks the application.
    Could you help me?

    Many thanks

    Ricardo Sousa

    Note: the Qtimer object is not in a different thread, but I suppose that it should work in this way.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tucnak
      wrote on last edited by
      #2

      Oh. QTimer is asynchronous - how it can block your application? OK. I will show you example:

      mainwindow.h
      @
      //...
      #include <QObject>
      #include <QTimer>
      #include <QDebug>

      class MainWindow : public QObject {
      Q_OBJECT
      public:
      MainWindow(QObject* parent = 0);
      public slots:
      void mySlot();
      private:
      QTimer * timer;
      }
      //...
      @

      mainwindow.cpp
      @
      MainWindow::MainWindow(QObject *parent = 0) :
      timer(new QTimer)
      {
      timer->setInterval(1000); // one second
      connect(timer, SIGNAL(timeout()), this, SLOT(mySlot()));
      timer->start();
      }

      void MainWindow::mySlot() // will be executed every second
      {
      qDebug() << "here it is";
      }
      @

      This code won't block application - it's asynchronous!

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hungnd
        wrote on last edited by
        #3

        Please post your code

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          Is it possible that your timeout value is too low (for the amount of work that has to be done in the connected slots) so the timer runs out consecutively and thus your applications thrashes and blocks?

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tucnak
            wrote on last edited by
            #5

            [quote author="Lukas Geyer" date="1339491711"]Is it possible that your timeout value is too low (for the amount of work that has to be done in the connected slots) so the timer runs out consecutively and thus your applications thrashes and blocks?[/quote]

            Oh. Yes. You may review your interval and slots, which connected with timer. It can be very small amount of time for hard work in slots, so they can be running all the time (without interval).

            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