Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QTextCursor::setPosition: Position 'xxxx' out of range (Warning) #12

Open
DonnKey opened this issue Aug 30, 2021 · 0 comments
Open

QTextCursor::setPosition: Position 'xxxx' out of range (Warning) #12

DonnKey opened this issue Aug 30, 2021 · 0 comments

Comments

@DonnKey
Copy link

DonnKey commented Aug 30, 2021

... xxxx seems to be the number of characters in the edit widget.

The warning apparently is associated with clearing the text document, where QtSpell doesn't recognize that the document is empty. (This is a guess.)

Repro: in gImageReader scan a (simple) document in text (not HOCR) mode, and then clear the scan in the Output window. At least that works for me always.

Stack trace. Notes imbedded

#0 raise (sig=5) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00005555556ff9b1 in myMessageOutput (type=QtWarningMsg, context=..., msg=...) at /home/donnt/gImageReader/qt/src/main.cc:117
#2 0x00007ffff6222e15 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#3 0x00007ffff6222fc8 in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#4 0x00007ffff61f524f in QMessageLogger::warning(char const*, ...) const () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5

----- The warning comes from here

#5 0x00007ffff68cc0ec in QTextCursor::setPosition(int, QTextCursor::MoveMode) () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5

----- There are 2 pairs of calls to setPosition in handleContentsChange. I think the document has been cleared by this point,
and there should be only one change - the initial insert of text from the scan, so it's probably the pair in the undo stack.
An empty document implies that there's no legal value for 'pos'.

#6 0x00007ffff79c972c in QtSpell::UndoRedoStack::handleContentsChange(int, int, int) () from /usr/lib/x86_64-linux-gnu/libqtspell-qt5.so.0
#7 0x00007ffff79c8415 in QtSpell::TextEditChecker::slotCheckRange(int, int, int) () from /usr/lib/x86_64-linux-gnu/libqtspell-qt5.so.0

---- Above is called from QTextDocument (2 below), apparently as a response to clearing the document, via a connect().

#8 0x00007ffff64077f6 in QMetaObject::activate(QObject*, int, int, void**) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#9 0x00007ffff6b0a74a in QTextDocument::contentsChange(int, int, int) () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#10 0x00007ffff689f60d in QTextDocumentPrivate::clear() () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#11 0x00007ffff6890324 in QTextDocument::clear() () from /usr/lib/x86_64-linux-gnu/libQt5Gui.so.5
#12 0x00007ffff6f2d5da in ?? () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#13 0x00007ffff6f378b4 in QWidgetTextControl::clear() () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#14 0x000055555560a483 in OutputEditorText::clear (this=0x555555c16ee0, hide=false) at /home/donnt/gImageReader/qt/src/OutputEditorText.cc:347 (line number won't match exactly)

---- problem initiated here in OutputEditorText::clear, at the call to ui.plainTextOutput->clear()

#15 0x000055555560def0 in QtPrivate::FunctorCall<QtPrivate::IndexesList<0>, QtPrivate::List, void, bool (OutputEditorText::)(bool)>::call (f=&virtual table offset 208, o=0x555555c16ee0, arg=0x7fffffffd000) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:134
#16 0x000055555560d9b4 in QtPrivate::FunctionPointer<bool (OutputEditorText::
)(bool)>::call<QtPrivate::List, void> (f=&virtual table offset 208, o=0x555555c16ee0, arg=0x7fffffffd000) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:167
#17 0x000055555560d16e in QtPrivate::QSlotObject<bool (OutputEditorText::)(bool), QtPrivate::List, void>::impl (which=1, this_=0x5555560942a0, r=0x555555c16ee0, a=0x7fffffffd000, ret=0x0) at /usr/include/x86_64-linux-gnu/qt5/QtCore/qobjectdefs_impl.h:396
#18 0x00007ffff6407933 in QMetaObject::activate(QObject
, int, int, void**) () from /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
#19 0x00007ffff6d52f02 in QAction::triggered(bool) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5
#20 0x00007ffff6d55520 in QAction::activate(QAction::ActionEvent) () from /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5

Is the off-by-one case noted in the comments in checkSlotRange either (now that that might be fixed?) the cause, or is there another special case to work around?

Workaround in gImageReader::OutputEditorText::clear (somewhere near line 330): add the setUndoRedoEnabled calls below:

			return false;
		}
	}
	m_spell.setUndoRedoEnabled(false); // added for workaround
	ui.plainTextEditOutput->clear();
	m_spell.setUndoRedoEnabled(true); // added for workaround
	m_spell.clearUndoRedo();
	ui.plainTextEditOutput->document()->setModified(false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant