Привет, я пытаюсь создать функцию для сканирования QTextEdit, поиска адресов электронной почты и номеров телефонов и выделения их жирным шрифтом. Когда я запускаю его, моя программа вылетает с ошибкой "QTextCursor::setPosition: Position '-1' out of range", вот код:
void MakeDisplay::processDoc(){
QString doc = text->toPlainText();
QTextCursor cursor = text->textCursor();
QTextCharFormat format;
format.setFontWeight(75);
QRegExp emails("*.@.*");
QRegExp phoneNums
("(\\d{3}-\\d{3}-\\d{4})(\\d{3}-\\d{7})(\\d{10})(\\(\\d{3}\\)\\d{3}-\\d{4})(\\(\\d{3}\\)\\d{7})");
int i, j;
i = 0;
j = 0;
while (!cursor.atEnd() || (i != doc.size())){
i = doc.indexOf(emails);
j = doc.indexOf(phoneNums);
cursor.setPosition(i,QTextCursor::MoveAnchor);
cursor.setPosition(i, QTextCursor::KeepAnchor);
cursor.mergeCharFormat(format);
cursor.setPosition(j,QTextCursor::MoveAnchor);
cursor.setPosition(j, QTextCursor::KeepAnchor);
cursor.mergeCharFormat(format);
i++;
j++;
}
}