QTextDocument *doc = new QTextDocument("Hello, world!"); // get the first block of text QTextBlock block = doc->begin(); // check if the block is valid before accessing its content if (block.isValid()) { QString text = block.text(); qDebug() << text; // "Hello, world!" }
QTextDocument *doc = new QTextDocument("This is line 1.\nThis is line 2.\nThis is line 3."); // loop through all blocks in the document and check if they are valid for (QTextBlock block = doc->begin(); block.isValid(); block = block.next()) { if (block.isValid()) { QString text = block.text(); qDebug() << text; } }Package/library: Qt C++ library.