I am working on a text editor I'm using Qt4.8/Pyqt specifically the QTextedit object.
Consider the following code(not orignal)

def doReplaceAll(self):
# Replace all occurences without interaction

# Here I am just getting the replacement data
# from my UI so it will be different for you
old=self.searchReplaceWidget.ui.text.text()
new=self.searchReplaceWidget.ui.replaceWith.text()

# Beginning of undo block
cursor=self.editor.textCursor()
cursor.beginEditBlock()

# Use flags for case match
flags=QtGui.QTextDocument.FindFlags()
if self.searchReplaceWidget.ui.matchCase.isChecked():
flags=flags|QtGui.QTextDocument.FindCaseSensitivel y

# Replace all we can
while True:
# self.editor is the QPlainTextEdit
r=self.editor.find(old,flags)
if r:
qc=self.editor.textCursor()
if qc.hasSelection():
qc.insertText(new)
else:
break

# Mark end of undo block
cursor.endEditBlock()

This works well for a few hundred lines of text. But when I have a lot of text say 10000 to 100000 lines of text replace all is EXTREMELY slow to the point of not being usable as the Editor slows right down.
Am I doing something wrong. Why is QTextEdit so slow, I tried QplaingTextEdit as well not much luck there either. Any suggestions?