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 set reminder in qt
Forum Updated to NodeBB v4.3 + New Features

How to set reminder in qt

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.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.
  • P Offline
    P Offline
    prabhatjha
    wrote on last edited by
    #1

    hello everyone i want to make reminder in qt...so first of all i set current time on a label and now i want to set alarm after 2 hours and when 2 hours will be complete there will be a message box open and that will remind us that your time have been completed. please give me some suggesion i know what will be logic use here but dont know how to implement in qt.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      prabhatjha
      wrote on last edited by
      #2

      this is my code what i used but i am getting error error: no match for 'operator-' in 'settime - CurrentTime'
      @
      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include<QTimer>
      #include<QTime>
      #include<qDebug>

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

      QTimer *timer = new QTimer(this);;
      timer->setInterval(60);
      connect(timer, SIGNAL(timeout()),this,SLOT(update_time()));
      timer->start();
      

      }

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

      void MainWindow::update_time()
      {
      ui->label_time->setText(QTime::currentTime().toString());

      QString CurrentTime = QTime::currentTime().toString();
      
      if ( ui->lineEdit->text() != "")
      {
          QString settime = ui->lineEdit->text();
          qDebug()<<settime;
      
          QString Diff = settime - CurrentTime;
      
          if (Diff == "00:00:00")
          {
              QMessageBox msgBox;
              msgBox.setText("Your time has been finished.");
          }
      }
      

      }
      @
      error: no match for 'operator-' in 'settime - CurrentTime'

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        You are trying to substract string... this will not work! You need to use QTime/ QDateTime classes here.

        (Z(:^

        1 Reply Last reply
        0
        • P Offline
          P Offline
          prabhatjha
          wrote on last edited by
          #4

          for current time i can use QTime currtime = QTime::currentTime() but what i should use for the time when i will set alarm ...let i want to set alarm after 2 hours then where i will store these time...please give me some solution ...thanks in advance.

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            @
            QTime currtime = QTime::currentTime();
            QTime alarmTime = currtime.addSecs(2 * 3600);
            @

            I would personally prefer to use QDateTime, which has addHours() method. Plus, you can actually set the timer to 2 hours and skip the whole QTime hassle.

            (Z(:^

            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