#ifndef PROGA1_H#define PROGA1_H#include <QMainWindow>#include <QTranslator>#include <QFile>#include <QObject>#include "ui_proga1.h"class MainWindow : public QMainWindow, Ui::MainWindow // <--------Наследуемся{ Q_OBJECTpublic: int iS, oS, oM, oH; QTranslator* translator; QFile* file; QString* str; MainWindow(QMainWindow* p = 0) : QMainWindow(p)..................
#ifndef PROGA1_H#define PROGA1_H#include <QMainWindow>#include <QTranslator>#include <QFile>#include <QObject>#include "ui_proga1.h"class MainWindow : public QMainWindow, Ui::MainWindow // <--------Наследуемся{ Q_OBJECTpublic: int iS, oS, oM, oH; QTranslator* translator; QFile* file; QString* str; MainWindow(QMainWindow* p = 0) : QMainWindow(p) { translator = new QTranslator(this); file = new QFile(this); setupUi(this);
#include <QApplication>#include <QTranslator>#include <QFile>#include <QtGui>#include <QString>#include <QTextStream>#include <QDate>#include "proga1.h" int main (int argc, char **argv) { QApplication app(argc, argv); //QSplashScreen splash(QPixmap("./image/zastavka.png")); QFile file("C:\\Pr1\\log.txt");//<<================ file.open(QIODevice::Append);//<<================ QTextStream out(&file); out << "|-------------------------------------------------------------|\r\n"; out << "| |\r\n"; out << "| |\r\n"; QString str = QDateTime::currentDateTime().toString("hh.mm.ss"); out << "| Log-file is created |\r\n"; out << "| |\r\n"; out << "| |\r\n"; out << "|-------------------------------------------------------------|\r\n"; str = QDateTime::currentDateTime().toString("hh.mm.ss"); out << str << " Program is running\r\n"; file.flush(); //<<=================== qDebug() << "after file.flush()"; MainWindow w; //loadModules(&splash) ; getchar(); //splash.finish(&w); w.show(); str = QDateTime::currentDateTime().toString("hh.mm.ss"); out << str << " Application is started\r\n"; file.close(); return app.exec(); }
...void MainWindow::closeEvent(QCloseEvent *event){ file->open(QIODevice::Append); QTextStream out(file); QString str = QDateTime::currentDateTime().toString("hh.mm.ss"); out << str << " Application finished " << "\r\n"; file->close(); event->accept();}
... void helpBrowser(); void logFile(); void closeEvent(QCloseEvent *event);
void MainWindow::helpBrowser(){ this->setWindowModality(Qt::NonModal); HelpBrowser* helpbrowser = new HelpBrowser("doc", "./help/index.html"); helpbrowser->setWindowTitle(tr("Help")); helpbrowser->resize(500, 400); helpbrowser->setMaximumSize(500, 400); helpbrowser->setMinimumSize(500, 400); helpbrowser->show(); //-------LOG QFile file("./log.txt"); file.open(QIODevice::Append); QTextStream out(&file); QString str = QDateTime::currentDateTime().toString("hh.mm.ss"); out << str << " Help browser is show\r\n"; file.flush(); file.close(); //-------endLog}
#include <QtGui>#include "proga1_about.h"MyAbout::MyAbout(QWidget *parent) : QWidget(parent){ setupUi(this); connect(pushButton, SIGNAL(pressed()), this, SLOT(close()));}bool MyAbout::event(QEvent* e){ if (e->type() == QEvent::LanguageChange) { retranslateUi(this); return true; } return QWidget::event(e);}void MyAbout::closeEvent(QCloseEvent *event){ QFile file("./log.txt"); file.open(QIODevice::Append); QTextStream out(&file); QString str = QDateTime::currentDateTime().toString("hh.mm.ss"); out << str << " About program is close " << "\r\n"; file.flush(); file.close(); event->accept();}