I'd like to have the code that appends the dat/time to the lable executed when each of the GUI elements is clicked.
How do I implement the "AddCurrentDateTime" function so that I can call that line of code whenever necessary?
Obviously the code below generated the error:
/home/wfdwfd/function/mainwindow.cpp:6: error: ‘ui’ was not declared in this scope
ui->label->setText(ui->label->text() + " " + QDateTime::currentDateTime().toString("yyyy MMM/dd h:mm:ss a t"));
^~
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QDateTime"
void AddCurrentDateTime() {
ui
->label
->setText
(ui
->label
->text
() + " " + QDateTime::currentDateTime().
toString("yyyy MMM/dd h:mm:ss a t"));
}
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->label->setText("Waiting on you Kiddo...so click something.");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
ui->label->setText("Push Button");
AddCurrentDateTime();
}
void MainWindow::on_radioButton_clicked()
{
ui->label->setText("Radio Button");
AddCurrentDateTime();
}
void MainWindow::on_checkBox_stateChanged(int arg1)
{
ui->label->setText("Checkbox");
AddCurrentDateTime();
}
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QDateTime"
void AddCurrentDateTime() {
ui->label->setText(ui->label->text() + " " + QDateTime::currentDateTime().toString("yyyy MMM/dd h:mm:ss a t"));
}
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->label->setText("Waiting on you Kiddo...so click something.");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
ui->label->setText("Push Button");
AddCurrentDateTime();
}
void MainWindow::on_radioButton_clicked()
{
ui->label->setText("Radio Button");
AddCurrentDateTime();
}
void MainWindow::on_checkBox_stateChanged(int arg1)
{
ui->label->setText("Checkbox");
AddCurrentDateTime();
}
To copy to clipboard, switch view to plain text mode
Bookmarks