Quote Originally Posted by dotjan View Post
Hi, I am using QTextCursor to move my cursor at the Start and at the End of my QTextEdit document.

Strangely, while I can move it to the Start with QTextCursor::Start, it seems it does not move to the end with QTextCursor::End

Here is my code

Qt Code:
  1. void MyPage::find(const QString &text, QTextDocument::FindFlags flags)
  2. {
  3. if ( !uiL->textEdit->find(text, flags) ) {
  4.  
  5. // if searching backward move cursor at the end
  6. if ( flags == QTextDocument::FindBackward ) {
  7.  
  8. QTextCursor mycursor;
  9. mycursor.movePosition(QTextCursor::End); // try here instead
  10. uiL->textEdit->setTextCursor(mycursor);
  11. }
  12.  
  13. // if searching foreward move cursor at the start
  14. if ( flags != QTextDocument::FindBackward ) {
  15. QTextCursor mycursor;
  16. uiL->textEdit->setTextCursor(mycursor);
  17. mycursor.movePosition(QTextCursor::Start); // THIS WORKS - actually, this doesnt do anything...
  18. }
  19.  
  20. // once cursor is moved search again. If return false than the word does not exist in the doc
  21. if ( !uiL->textEdit->find(text, flags) ) {
  22. qDebug()<<"Not found";
  23. }
  24. }
  25. }
To copy to clipboard, switch view to plain text mode 

So basically when I am searching backward I always get "Not Found" when reached the top, I would expect to find the first occurrence from the bottom instead. DOes it make sense?

Thanks,
Jan
see code changes

do you know the reason why your way cannot work?