You need to get plain text and split it line by line. For instance:
QStringList lines = plainTextEdit->plainText() .split('\n', QString::SkipEmptyParts); if (lines.count() > 3) qDebug() << "fourth line:" << lines.at(3);
If you want to include blank lines, remove the SkipEmptyParts argument - the default is KeepEmptyParts .
You can also use a text stream:
QString text = plainTextEdit->plainText(); QTextStream str(&text, QIODevice::ReadOnly); QString line; for (int n = 0; !str.atEnd() && n < 3; ++n) line = str.readLine(); qDebug() << "fourth or last line:" << line;
source share