QTextCursor cursor = textEdit->textCursor(); // Assumes a QTextEdit widget named 'textEdit' // Set the anchor at the current cursor position cursor.setPosition(cursor.position(), QTextCursor::KeepAnchor); cursor.setAnchor(true); // Later, retrieve the anchor QTextCursor anchorCursor = cursor.document()->findBlockByNumber(cursor.anchor());This code sets an anchor at the current cursor position in a QTextEdit widget, then later retrieves the anchor by finding the block of text containing the anchor position. The package library for QTextCursor is part of the Qt library.