Results 1 to 7 of 7

Thread: QTextEdit::keyPressEvent leads to 0xC0000005 Access Violation Error

  1. #1
    Join Date
    Jun 2009
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Lightbulb QTextEdit::keyPressEvent leads to 0xC0000005 Access Violation Error

    I'm really stuck on this one, so i'll explain the situation and hopefully one of the professional programmers here will easily detect the error.

    I recently updates from Qt4.4 to Qt4.6. The code was not changed, worked before but now leads to an error in debug.

    I defined a custom TextEdit class with parent QTextEdit. This class has an overloaded keyPressEvent-function, which checks for a few keys and otherwise calls the parent keyPressEvent with: QTextEdit::keyPressEvent(event);
    I build the program, run it, and if i typed in something everything worked fine.
    However after the update there is an Access Violation Error apearing while executing this line.
    The error appears in the file free.c, line 109: retval = HeapFree(_crtheap, 0, pBlock);
    It only appears when the Backspace-Key or the Delete-Key are pressed, maybe on other keys which i haven't found yet. And it fails not everytime, but around 90%. If i type in letters or use the tab it works fine.

    If i remove the line in which the parent function is called there is no error (and no QTextEdit::keyPressEvent(event) called). If i remove the overloaded function completely so only the QTextEdit::keyPressEvent(event) is called the error still appears.

    My thought was that the keyPressEvent may be called multiple times and that is conflicting with the memory, but that is not the case. the keyPressEvent is only called once, in this line. The problem appears independant on the computer it's executed on. Maybe someone knows what i could have done wrong, or if it's just a Qt bug with the version update. I looked through the Changelist for QTextEdit but didn't find anything useful which has changed the way a keyPressEvent is used.
    Last edited by android_; 12th March 2010 at 12:09.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QTextEdit::keyPressEvent leads to 0xC0000005 Access Violation Error

    Maybe someone knows what i could have done wrong, or if it's just a Qt bug with the version update.
    If it is a Qt bug, it will apear if you use a regular QTextEdit.
    If it only apears with your custom class, then its a bug in your code.
    retval = HeapFree(_crtheap, 0, pBlock);
    You have a heap corruption.
    The nasty thing about heap corruption is that it very often crashes NOT where the corruption really occurs , but usually when some memory is baying freed (and thus checked, which triggers the assertion).
    Look at all the heap allocated variables in your class, and make sure you are not reading or writing beyond their allocated address.
    Dangling references (that is, reference on a variable out of scope) can also have similar behavior.
    This also fits well to the fact that it happens not always, and different between systems.

    OR/AND - if you are using threads, then it could be a any number of thread related problems.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

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

    android_ (12th March 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit::keyPressEvent leads to 0xC0000005 Access Violation Error

    Showing us some code would be helpful too.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #4
    Join Date
    Jun 2009
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextEdit::keyPressEvent leads to 0xC0000005 Access Violation Error

    .............
    Last edited by android_; 14th March 2010 at 15:22.

  6. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit::keyPressEvent leads to 0xC0000005 Access Violation Error

    0xC... address is on the stack, not on the heap. Most likely your application tries to delete a stack-based object. Please show us the complete backtrace after the crash.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #6
    Join Date
    Jun 2009
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextEdit::keyPressEvent leads to 0xC0000005 Access Violation Error

    I traced it down to two functions which were not members of the custom QTextEdit, but connected to specific signals. Thanks for your help.

    If i cannot get it to run i'll work out how to do a complete backtrace and post it.

  8. #7
    Join Date
    Jun 2009
    Posts
    13
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextEdit::keyPressEvent leads to 0xC0000005 Access Violation Error

    Apparently the modification of the QTextCursor was the source of the error.
    I don't know why it was not working (probably unvalid position because of the backspace?) but i changed a few things and now it works fine.
    Strange nevertheless.

Similar Threads

  1. OpenCV causes access violation only during timerEvent
    By derekkingston in forum Qt Programming
    Replies: 5
    Last Post: 19th February 2010, 08:56
  2. Replies: 5
    Last Post: 17th June 2009, 14:01
  3. Access violation when reading big text files
    By robertson1 in forum General Programming
    Replies: 0
    Last Post: 18th September 2008, 06:59
  4. Access Violation on Signal Emit
    By khagzan in forum Qt Programming
    Replies: 2
    Last Post: 25th September 2007, 22:51
  5. 0xc0000005 when linking against lib
    By niko in forum Qt Programming
    Replies: 10
    Last Post: 8th March 2006, 08:55

Tags for this Thread

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.