How to retrieve text ?
-
I have some understanding of the concept , but I really need step by step explanation what is the code doing.
I have look at few examples and they do not explain what each class in trying to do .
And things are more confusing since my code is already running in QTextEdit object.
It would help to know what is each lineof code doing. At this point I am not concerned if the code copiles , I just need
verbal desription of each.-
QTextDocument instance does ... ( links to actuall QTextEdit "text" ? If so how ? )
-
QTextCurson instance does... ( links to instance of QTextDocument physical cursor ?
etc ....
QTextDocument *document = new QTextDocument(); QTextCursor cursor(document); // put visible cursor to the end of the line QTextCursor cursor = QTextEdit::textCursor(); cursor.movePosition(QTextCursor::StartOfLine); //::End); setTextCursor(cursor); -
-
QTextDocument *document = new QTextDocument(); // ^^^ a new empty QTextDocument QTextCursor cursor(document); // ^^^ an object that represents position in the text of the document above (there is none) // put visible cursor to the end of the line // ^^^ A QTextDocument is an in-memory structure representing a document, there is no "visible" QTextCursor cursor = QTextEdit::textCursor(); // ^^^ This should not compile, there is no static QTextEdit::textCursor() // If you went: QTextCursor cursor = textEdit->textCursor(); // then you would have an object that represented a location within the document that // the text edit is currently displaying a visible cursor at. // This is *not* the document created above. // The QTextDocument being displayed by a QTextEdit is obtained with textEdit->document() // https://doc.qt.io/qt-6/qtextedit.html#document-prop cursor.movePosition(QTextCursor::StartOfLine); // Move the cursor object to point at the start of the line in the QTextDocument // object it is related to. // This does *not* move the visible cursor in the QTextEdit. setTextCursor(cursor); // Assuming this is called on the textEdit object then the visible cursor should // move to the location corresponding to the cursor object's location in the document. // In this case, where the start of the document line is present on the screen. // A document line , and a line on screen, do not necessarily mean the same thing // because a single document line can be wrapped.Nothing in this code retrieves text, so I do not see how it is related to the question posed in the title.