-
-
Save vojtechkral/c98f6ad33c099a9f9a9f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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