Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7076437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:17:54+00:00 2026-05-28T06:17:54+00:00

I am writing a simple task planner and reminder using Qt which will play

  • 0

I am writing a simple task planner and reminder using Qt which will play a sound file when the date and time of any given task matches with the the current date and time.

To implement this, I am running a QThread which checks the task in the list to see if any match the current time and if so, plays the sound file.

This id my original class:

class Task
{
  public:
      QString ta, desc;
      QTime ti;
      QDate da;
      int pri, diff;
      bool ala;
};  

This is my Thread Class:

class AlarmCheck : public QThread
{
  public:
      void setTask(QList<Task>);
      void run();
      bool isRunning;
      QString music;
      QTime alarmOffset;

  private:
      QList<Task> list;
};

My Implementation:

void AlarmCheck::setTask(QList<Task> l)
{
    list = l;
}

void AlarmCheck::run()
{
    while(isRunning)
    {
        foreach(Task t, list)
        {
            if((t.da == QDate::currentDate()) && (t.ti == QTime::currentTime()) && t.ala)
            {
                Phonon::MediaObject *gaana =
                        Phonon::createPlayer(Phonon::MusicCategory,
                                              Phonon::MediaSource(music));
                gaana->play();
                QMessageBox::information(NULL,
                                         "Alarm!!!",
                                         "The time has come for\n"
                                         + t.ta +
                                         "\n Time to do it!");
                gaana->stop();
            }
            qDebug("Curr = " + QTime::currentTime().toString().toAscii() + " Date = " + QDate::currentDate().toString().toAscii());
            qDebug("Task = " + t.ti.toString().toAscii() + " Date = " + t.da.toString().toAscii());                
        }
        sleep(1);
    }
}  

The thing is that the thread is running perfectly, but the if() condition inside the foreach() loop is never satisfied for some reason. I even checked the individual date/time/alarm setting (t.ala) using qDebugs (as you can see); they are all fine.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:17:54+00:00Added an answer on May 28, 2026 at 6:17 am

    Your if statement requires that the date and time match exactly, down to the millisecond. It is unlikely that your loop will evaluate at this exact moment. If you want to maintain similar logic (processing tasks in a loop), you might try sorting them by “next task first” (or perhaps using a queue), then testing in your if statement if the current QDateTime is equal-to-or-greater than the task date/time of the first task.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a simple Word Interop application which open a .doc file in
Is there a relatively simple way in nant, without writing a custom task, to
Trying to do the simple task of writing to the registry to make a
I'm writing app for android device, which is simple download manager. I want to
I'm writing a simple generic logger class, that is aware of time started and
I'm writing a simple request handler to return a pair of css files. Using
I have a rather simple threading question. I'm writing a simple utility that will
I'm writing a fairly simple app which, upon a fatal error, displays a dialog
I'm writing simple program to communicate between smart devices and I receive 11001 when
I'm looking into writing simple graphics code in Android and I've noticed some synchronized()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.