简体   繁体   中英

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.

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();

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