QTextEdit *editor = new QTextEdit(); QTextCursor cursor = editor->textCursor(); int blockNum = cursor.blockNumber(); qDebug() << "Current block number: " << blockNum;
QTextDocument *doc = new QTextDocument(); QTextCursor cursor(doc); cursor.insertText("Hello\nWorld\n"); cursor.movePosition(QTextCursor::Start); cursor.movePosition(QTextCursor::Down); int blockNum = cursor.blockNumber(); qDebug() << "Current block number: " << blockNum;This example creates a QTextDocument object and a QTextCursor object to manipulate the document. Text is inserted into the document, and the cursor is moved to the second line using the movePosition function with the QTextCursor::Down argument. The blockNumber function is then used to get the block number of the current position, which is printed to the console. In both examples, the QTextCursor class comes from the Qt library's QtCore module.