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 event Slot 1 minute before
Forum Updated to NodeBB v4.3 + New Features

Qtimer event Slot 1 minute before

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.7k 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.
  • E Offline
    E Offline
    enaud84
    wrote on last edited by
    #1

    How can I set a timer that run an event slot 1 minute before of signal event

    for example in mainwindow:

    @
    Qtimer *timer9 = new Qtimer(this);
    connect(timer9, SIGNAL(timeout()), this, SLOT(arrivopullman()));
    timer9->start(180000); // 3 minutes
    @

    @
    void MainWindow::arrivopullman(){
    /* if timer9:value = timer:value - 120000{
    ui->label2->show();
    }
    if timer9:value=180000
    ui->label2->close();
    ui->label5->show();
    }
    */
    }
    @

    I would not put 2-3 different timers, I would do it all with one, is possible?

    thanks for help

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      How should the new timer know when an event is signaled?

      In your case you probably mean you like to have a trigger after 2 min and after 3 min. there are different implementations possible. But you need to trigger first the 2 min event with a timer. In the slot of this event you can set for instance a single shot timer for starting the 3min event.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • E Offline
        E Offline
        enaud84
        wrote on last edited by
        #3

        in this image is easier to understand what I wanna do:

        !http://img198.imageshack.us/img198/5408/immagineogj.jpg(Click here)!

        at 2 minute to do
        ui->label2->show();
        at 3 minute to do
        ui->label2->close();
        ui->label3->show();

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          I though that you were trying something like this.

          Personally I would write two slot methods. Use a singleshot timer to start the 2min slot and start then the first time a regular 3 min timer starting starting always this slot again. Every time the 2min slot is triggered it start a singleshot timer with 60 seconds. This singleshot timer shall trigger the 3min slot.

          Vote the answer(s) that helped you to solve your issue(s)

          1 Reply Last reply
          0
          • R Offline
            R Offline
            RaubTieR
            wrote on last edited by
            #5

            I'd even suggested having 2 slots and in slot#1 you start with single-shoting slot#2 in one sec, also in slot#2 you will make a single-shot for slot#1 that comes in 2 sec... Like so:

            @#include "mainwindow.hpp"
            #include "ui_mainwindow.h"

            #include <QTimer>

            const int delay1 = 2000, delay2 = 1000;
            quint64 Counter = 0; // a counter of passed time for this example

            MainWindow::MainWindow(QWidget *parent) :
            QMainWindow(parent),
            ui(new Ui::MainWindow)
            {
            ui->setupUi(this);

            // lets say we have a label on form, and we show Counter value
            ui->lblShots->setText(QString("%1").arg(Counter));

            // sequence hasshin
            QTimer::singleShot(delay1, this, SLOT(slot1()));
            }

            MainWindow::~MainWindow()
            {
            delete ui;
            }

            void MainWindow::slot1()
            {
            // a requesting the next shot
            QTimer::singleShot(delay2, this, SLOT(slot2()));

            // here we do whatever business we have
            Counter += delay1;
            ui->lblShots->setText(QString("%1").arg(Counter));
            }
            void MainWindow::slot2() // same here
            {
            QTimer::singleShot(delay1, this, SLOT(slot1()));

            Counter += delay2;
            ui->lblShots->setText(QString("%1").arg(Counter));
            }@

            1 Reply Last reply
            0
            • E Offline
              E Offline
              enaud84
              wrote on last edited by
              #6

              ok thanks all for your helps.

              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