Thank you Sebastian!
Ive actually switched to using separate QDate and QTime edit fields now.
As I have it, the user launches the app and the QDate and QTime edit fields will show their respective current date and time until the user changes them. These fields do not update like the current time clock I have running in a label.
I want the edited date and time to only be updated/reflected in the rest of the program when the user presses the "Set Alarm" button, NOT when they edit the fields.
Do I put setEnabled(false) in the "editingFinished(etc...) function of the date/ time edit fields?
Maybe it would be more helpful if I post my code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
public slots:
void setDate
(const QDate &date
);
void setTime
(const QTime &time
);
private slots:
void showTime();
void setAlarm();
void cancelAlarm();
void on_setAlarm_clicked();
void on_cancelAlarm_clicked();
// void on_dateTimeEdit_dateTimeChanged(const QDateTime &dateTime);
// void on_dateTimeEdit_editingFinished(const QDateTime &dateTime);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
public slots:
void setDate(const QDate &date);
void setTime(const QTime &time);
private slots:
void showTime();
void setAlarm();
void cancelAlarm();
void on_setAlarm_clicked();
void on_cancelAlarm_clicked();
// void on_dateTimeEdit_dateTimeChanged(const QDateTime &dateTime);
// void on_dateTimeEdit_editingFinished(const QDateTime &dateTime);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
and
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
#include <QDateTime>
#include <QDateTimeEdit>
#include <QTimeEdit>
#include <QDateEdit>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
showTime();
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start();
ui
->timeEdit
->setTime
(QTime::currentTime());
ui
->dateEdit
->setDate
(QDate::currentDate());
}
void MainWindow::showTime()
{
// QDate date =
QString time_text
= time.
toString("hh : mm");
ui->Digital_Clock->setText(time_text);
}
void MainWindow::on_setAlarm_clicked()
{
setTime(time);
}
void MainWindow::on_cancelAlarm_clicked()
{
cancelAlarm();
}
void MainWindow
::setDate(const QDate &date
) {
}
void MainWindow
::setTime(const QTime &time
) {
}
void MainWindow::setAlarm()
{
}
void MainWindow::cancelAlarm()
{
}
MainWindow::~MainWindow()
{
delete ui;
}
//void MainWindow::on_dateTimeEdit_dateTimeChanged(const QDateTime &dateTime)
//{
//bool flag = 1;
//}
//void MainWindow::on_dateTimeEdit_editingFinished(const QDateTime &dateTime)
//{
// QDateTime dateTimeFromText(dateTime);
//}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QTimer>
#include <QDateTime>
#include <QDateTimeEdit>
#include <QTimeEdit>
#include <QDateEdit>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
QDateTime *dateTime = new QDateTime;
ui->setupUi(this);
showTime();
QTimer * timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start();
ui->timeEdit->setTime(QTime::currentTime());
ui->dateEdit->setDate(QDate::currentDate());
}
void MainWindow::showTime()
{
// QDate date =
QTime time = QTime::currentTime();
QString time_text = time.toString("hh : mm");
ui->Digital_Clock->setText(time_text);
}
void MainWindow::on_setAlarm_clicked()
{
setTime(time);
setDate(QDate &date);
}
void MainWindow::on_cancelAlarm_clicked()
{
cancelAlarm();
}
void MainWindow::setDate(const QDate &date)
{
}
void MainWindow::setTime(const QTime &time)
{
}
void MainWindow::setAlarm()
{
}
void MainWindow::cancelAlarm()
{
}
MainWindow::~MainWindow()
{
delete ui;
}
//void MainWindow::on_dateTimeEdit_dateTimeChanged(const QDateTime &dateTime)
//{
//bool flag = 1;
//}
//void MainWindow::on_dateTimeEdit_editingFinished(const QDateTime &dateTime)
//{
// QDateTime dateTimeFromText(dateTime);
//}
To copy to clipboard, switch view to plain text mode
Bookmarks