[Development] Qt bug (crash on drag-n-drop on QPlainTextEdit)

Thiago Radicchi Roque trr at cadence.com
Wed Apr 25 07:37:33 CEST 2018


Recently I ran into a crash while doing drag-n-drop on some application that uses QPlainTextEdit from Qt 4.6.3. The crash happens when the text being dropped is large, causing the QPlainTextEdit to have a vertical scroll bar. I was able to fix it with the following patch:

diff -r 15465e31ff34 -r f8e5f70a5f95 src/gui/widgets/qplaintextedit.cpp
--- a/src/gui/widgets/qplaintextedit.cpp Thu Apr 12 14:41:58 2018 -0700
+++ b/src/gui/widgets/qplaintextedit.cpp             Mon Apr 23 16:21:28 2018 +0530
@@ -673,7 +673,8 @@
     QRectF lr = br;
     QTextLine line = block.layout()->lineForTextPosition(position - block.position());
-    Q_ASSERT(line.isValid());
+    if (!line.isValid())
+        return;
     lr = line.naturalTextRect().translated(br.topLeft());
     if (lr.bottom() >= visible.bottom() || (center && lr.top() < visible.top()) || forceCenter){

Apparently this has been reported before here https://bugreports.qt.io/browse/QTBUG-30018 , and fixed only in the Qt Creator. I didn’t run into the Q_ASSERT because I didn’t try it with a debug version of Qt.


  1.  Is this the right way to fix the problem?
  2.  Is it fixed in Qt5? I don’t think so, but I am not sure.
  3.  If this is the right fix, can someone please submit it on my behalf?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20180425/c64b7ad8/attachment.html>

More information about the Development mailing list