Skip to content

Instantly share code, notes, and snippets.

@vojtechkral
Created June 22, 2015 23:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vojtechkral/c98f6ad33c099a9f9a9f to your computer and use it in GitHub Desktop.
Save vojtechkral/c98f6ad33c099a9f9a9f to your computer and use it in GitHub Desktop.
// widget.h:
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QScopedPointer>
#include <QDate>
namespace Ui { class Widget; }
class Widget: public QWidget
{
Q_OBJECT
private:
QScopedPointer<Ui::Widget> ui;
private slots:
void compute(QDate = QDate());
public:
Widget();
virtual ~Widget();
};
#endif //WIDGET_H
// widget.cpp:
#include "widget.h"
#include "ui_widget.h"
Widget::Widget()
:ui(new Ui::Widget)
{
ui->setupUi(this);
compute();
}
Widget::~Widget() {}
void Widget::compute(QDate)
{
auto days = qAbs(ui->date1->date().daysTo(ui->date2->date()));
ui->lResult->setText(
QString("There is %1 day(s) between %2 and %3").arg(days)
.arg(ui->date1->date().toString(), ui->date2->date().toString()));
}
// main.cpp:
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment