Results 1 to 3 of 3

Thread: cursor.atEnd returns true, cursor is at start?

  1. #1
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default cursor.atEnd returns true, cursor is at start?

    I am clearly doing something stupid that a newbie does, but I can't solve this. Here is my test code:
    Qt Code:
    1. ui->TextEdit->setPlainText("testing\n");
    2. QTextCursor cursor( ui->TextEdit->textCursor() );
    3. cursor.movePosition (QTextCursor::End, QTextCursor::MoveAnchor);
    4. if(cursor.atEnd())
    5. {
    6. ui->TextEdit->insertPlainText("true\n");
    7. };
    To copy to clipboard, switch view to plain text mode 
    This prints:

    true
    testing

    I would expect the lines in different order. What am I missing?

  2. #2
    Join Date
    Nov 2008
    Location
    Częstochowa/Poland
    Posts
    50
    Thanks
    2
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: cursor.atEnd returns true, cursor is at start?

    The Qt doc clearly states.

    QTextCursor QTextEdit::textCursor () const

    Returns a copy of the QTextCursor that represents the currently visible cursor. Note that changes on the returned cursor do not affect QTextEdit's cursor; use setTextCursor() to update the visible cursor.

    just use the moveCursor method form QTextEdit

  3. The following user says thank you to Grimlock for this useful post:

    JuKu (2nd October 2009)

  4. #3
    Join Date
    Sep 2009
    Posts
    4
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: cursor.atEnd returns true, cursor is at start?

    I did read the documentation, but clearly from a wrong place. Besides, you can't always rely on snippets from the Internet, as demonstrated. Thanks for pointers!

Similar Threads

  1. connect() returns true but slot not called
    By OriginalCopy in forum Qt Programming
    Replies: 6
    Last Post: 4th November 2007, 18:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.