Jaime SPA
Jaime SPA

Reputation: 75

How to write in different line in Qt?

I would like to save in a .txt two lineEdit but in different line. It is together on the same line.

if(sFile.open(QFile::WriteOnly | QFile::Text))
    {
        QTextStream out(&sFile);

        out << ui.lineEdit_2->text();
        out << ui.lineEdit->text();

        sFile.flush();
        sFile.close();
    }

PD: The text I'm putting in Qt Designer with LineEdit.

Upvotes: 1

Views: 170

Answers (1)

Tim Meyer
Tim Meyer

Reputation: 12600

You can use endl or "\n" (n for "new line"). This is not Qt specific, but C++ in general:

out << ui.lineEdit_2->text() << "\n" 
    << ui.lineEdit->text();

Upvotes: 4

Related Questions