I tried some different options, and found a solution:
void MainWindow::saveSettings()
{
name = (QCoreApplication::applicationDirPath() +"/logs/"+ui->lineEdit->text() +".txt");
QFile file (name) ;
if (newfile == true){
if (file.exists()){
qDebug ()<<"already exists";
NewLog();
timer->stop();
} else {
qDebug()<< "Does not exist";
file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append);
QString c_time = QTime::currentTime().toString();
QString sText =QString::number(update) + ". "+ c_time + ": rpm = "+ rpm + ", load = "+ QString::number(load) + ", "
+ name1+ " = " + result1 + ", "+ name2+ " = " + result2 + ", "
+ name3+ " = " + result3 + ", "+ name4+ " = " + result4 + ", "
+ name5+ " = " + result5 + ", "+ name6+ " = " + result6 + ", "
+ name7+ " = " + result7 + ", "+ name8+ " = " + result8 + ", "
+ name9+ " = " + result9 + ", "+ name10+ " = " + result10;
ui->label_log->setText(sText);
update++;
QTextStream out(&file);
out << sText + "\n";
file.close();
newfile = false;
}}else{
file.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append);
QString c_time = QTime::currentTime().toString();
QString sText =QString::number(update) + ". "+ c_time + ": rpm = "+ rpm + ", load = "+ QString::number(load) + ", "
+ name1+ " = " + result1 + ", "+ name2+ " = " + result2 + ", "
+ name3+ " = " + result3 + ", "+ name4+ " = " + result4 + ", "
+ name5+ " = " + result5 + ", "+ name6+ " = " + result6 + ", "
+ name7+ " = " + result7 + ", "+ name8+ " = " + result8 + ", "
+ name9+ " = " + result9 + ", "+ name10+ " = " + result10;
ui->label_log->setText(sText);
update++;
QTextStream out(&file);
out << sText + "\n";
file.close();
}}
Maybe it can be easier, but i am still learning. Thanks for your input.
If you have comments on how to change my code, please tell me.
(newlog was only to test something else now)