简体   繁体   中英

Save data from spinbox

I have a problem with qt creator. I want to save data from my spinbox (7 exactly) to a text file (line by line) with the getSaveFileName function. I dont know how to do it. This is my code so fare.

ui->F0->value();
ui->Fs->value();
ui->c->value();
ui->N_elements->value();
ui->N_active->value();
ui->element_height->value();
ui->focus->value();

QString chemin = QFileDialog::getSaveFileName(this, "Enregistrer le fichier", m_chemin,"File (*.txt)");
QFile file(chemin);
if(!file.open(QIODevice::WriteOnly))
return;
QFile test=ui->F0->value() << endl<< ui->Fs->value() << endl<< ui->c->value()<< endl << ui->N_elements->value() << endl<< ui->N_active->value() << endl<< ui->element_height->value()<< endl<< ui->focus->value();;
QString extension=  QFileInfo(chemin).suffix();
test.save(chemin, extension.toAscii());

any help please

You should try something like that:

QFile * _log;
QString logDirPath = "path/to/file";
QDir logDir(logDirPath);
if(!logDir.exists()) {
    QDir().mkdir(logDirPath);
}
_log = new QFile(logDirPath + "test" + ".log");           
_log->open(QIODevice::ReadWrite | QIODevice::Text);
QTextStream ts(_log);
ts << ui->F0->value() << endl;
ts << ui->Fs->value() << endl;
ts << ui->c->value() << endl;
ts << ui->N_elements->value() << endl;
ts << ui->N_active->value() << endl;
ts << ui->element_height->value() << endl;
ts << ui->focus->value() << endl;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM