Skip to content

Instantly share code, notes, and snippets.

@scope2229
Created April 16, 2018 14:38
Show Gist options
  • Save scope2229/22ad9c48cab35e6777a6f2b75a732fe9 to your computer and use it in GitHub Desktop.
Save scope2229/22ad9c48cab35e6777a6f2b75a732fe9 to your computer and use it in GitHub Desktop.
//set up for the date and time labels
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));
timer->start(1000);
showTime();
QDateTime dateTime = dateTime.currentDateTime();
QString dateTimeString = dateTime.toString("dddd dd/MM/yyyy");
QString errorDateTimeString = dateTime.toString("dd/MM/yy hh:mm:ss");
ui->showDateLabel->setText(dateTimeString);
//set up for the errorLogs
QString errorLogsName = "Logs.txt";
QFile errorLogs(errorLogsName);
if (QFileInfo::exists("Logs.txt"))
{
ui->statusBar->showMessage("[+] Logging activated",5);
errorLogs.open(QIODevice::ReadWrite | QIODevice::Text);
QTextStream errorStream(&errorLogs);
errorStream << errorDateTimeString + ":OLD LOG: Logging activated for new session \n"; //later ill add computer name etc
errorLogs.flush();
errorLogs.close();
}
else
{
ui->statusBar->showMessage("Logging error file does not exist, creating Logs");
errorLogs.open(QIODevice::ReadWrite | QIODevice::Text);
errorLogs.write("Logs.txt \n");
ui->statusBar->showMessage("Logging file created",2);
QTextStream errorStream(&errorLogs);
errorStream << errorDateTimeString + ":New Log: Logging activated for new session \n"; //later ill add computer name etc
errorLogs.flush();
errorLogs.close();
ui->statusBar->showMessage("Ready to connect to the database!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment