QFile file("./log.txt"); file.open(QIODevice::WriteOnly); QTextStream out(&file); out << "This is log-file\r\n"; out << "This is :)\r\n"; file.close();
QString str; QDateTime::currentDateTime().toString(str); file.open(QIODevice::WriteOnly); QTextStream out(&file); out << str << " This is log-file\r\n"; out << str << " This is :)\r\n"; file.close();
void MainWindow::openFile(){ QString fileName = QFileDialog::getOpenFileName(".", "all(*.*)", this, (tr("File select"))); QFile file1(fileName); if (file1.open(QIODevice::ReadOnly)) { QTextStream stream(&file1); while (!stream.atEnd()) { textInput->setText(stream.read()); } } file1.close();}
Пн 28. дек 16:14:27 2009 This is log-file
void MainWindow::logFile(){ QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "C:\\Pr1", tr("Text files (*.txt)")); QFile file1(fileName); if (file1.open(QIODevice::ReadOnly)) { QTextStream stream(&file1); textInput->setText(stream.readAll()); } file1.close();}
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "C:\\Pr1", tr("Text files (*.txt)"));
int main (int argc, char **argv) { QApplication app(argc, argv); QSplashScreen splash(QPixmap("./image/zastavka.png")); QFile file("./log.txt"); file.open(QIODevice::WriteOnly); 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"; splash.show(); 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::rasschet(){ int notH, notM; //Объявление переменных const int SiH=3600, SiM=60; QString inSec; textEdit->clear(); inSec = spinBox->text(); //Ввод qDebug() << inSec; iS = inSec.toInt(); file->open(QIODevice::WriteOnly); QTextStream out(file); QString str = QDateTime::currentDateTime().toString("hh.mm.ss"); out << str << " Input number: " << iS << "\r\n"; qDebug() << iS; //Вычисление oH = (iS / SiH); //Количество часов notH = iS - (oH * SiH); //Убираем количество часов oM = (notH / SiM); //Количество минут notM = notH - (oM * SiM); //Убираем количество минут oS = notM; //Оставшееся число равно количеству секунд textEdit->setText(tr("The entered number of seconds %1 corresponds %2 hours, %3 minutes, %4 seconds").arg(iS).arg(oH).arg(oM).arg(oS)); str = QDateTime::currentDateTime().toString("hh.mm.ss"); out << str << iS << " corresponds " << oH << ":" << oM << ":" << oS << "\r\n";}
void MainWindow::rasschet(){ int notH, notM; //Объявление переменных const int SiH=3600, SiM=60; QString inSec; textEdit->clear(); inSec = spinBox->text(); //Ввод qDebug() << inSec; iS = inSec.toInt(); file->open(QIODevice::WriteOnly); QTextStream out(file); QString str = QDateTime::currentDateTime().toString("hh.mm.ss"); out << str << " Input number: " << iS << "\r\n"; qDebug() << iS; //Вычисление oH = (iS / SiH); //Количество часов notH = iS - (oH * SiH); //Убираем количество часов oM = (notH / SiM); //Количество минут notM = notH - (oM * SiM); //Убираем количество минут oS = notM; //Оставшееся число равно количеству секунд textEdit->setText(tr("The entered number of seconds %1 corresponds %2 hours, %3 minutes, %4 seconds").arg(iS).arg(oH).arg(oM).arg(oS)); str = QDateTime::currentDateTime().toString("hh.mm.ss"); out << str << iS << " corresponds " << oH << ":" << oM << ":" << oS << "\r\n"; file -> close();}