Problem with highlighting a character in a text
-
Hello Everybody,
I have a problem when i highlight a certain letter in a text, if the call to highligh happens only relatively fast, otherwise it is fine.
I am programming on MAC 10.7 with QT 4.8
here is the bugreport
@
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x00007fff87342ce2 __pthread_kill + 10
1 libsystem_c.dylib 0x00007fff87b057d2 pthread_kill + 95
2 libsystem_c.dylib 0x00007fff87af6a7a abort + 143
3 libsystem_c.dylib 0x00007fff87b184ac szone_error + 459
4 libsystem_c.dylib 0x00007fff87b184e8 free_list_checksum_botch + 29
5 libsystem_c.dylib 0x00007fff87b1f38c tiny_malloc_from_free_list + 145
6 libsystem_c.dylib 0x00007fff87b2000e szone_malloc_should_clear + 1115
7 libsystem_c.dylib 0x00007fff87b553c8 malloc_zone_malloc + 77
8 com.apple.CoreFoundation 0x00007fff90149d38 __CFBasicHashRehash + 344
9 com.apple.CoreFoundation 0x00007fff901848ba CFDictionaryCreate + 106
10 QtGui 0x0000000100721582 QCoreTextFontEngineMulti::stringToCMap(QChar const*, int, QGlyphLayout*, int*, QFlagsQTextEngine::ShaperFlag, unsigned short*, HB_CharAttributes const*, QScriptItem*) const + 274
11 QtGui 0x00000001009a8ccf QTextEngine::shapeTextMac(int) const + 895
12 QtGui 0x00000001009a953e QTextEngine::shapeText(int) const + 206
13 QtGui 0x00000001009a9907 QTextEngine::shape(int) const + 135
14 QtGui 0x00000001009b36c0 QTextLine::layout_helper(int) + 5328
15 QtGui 0x00000001009f48dd QTextDocumentLayoutPrivate::layoutBlock(QTextBlock const&, int, QTextBlockFormat const&, QTextLayoutStruct*, int, int, QTextBlockFormat const*) + 4029
16 QtGui 0x00000001009fadbb QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::iterator, QTextLayoutStruct*, int, int, QFixed) + 4331
17 QtGui 0x00000001009f54f7 QTextDocumentLayoutPrivate::layoutCell(QTextTable*, QTextTableCell const&, QFixed, int, int, QTextTableData*, QFixed, bool) + 967
18 QtGui 0x00000001009f7430 QTextDocumentLayoutPrivate::layoutTable(QTextTable*, int, int, QFixed) + 7232
19 QtGui 0x00000001009f85d7 QTextDocumentLayoutPrivate::layoutFrame(QTextFrame*, int, int, QFixed, QFixed, QFixed) + 743
20 QtGui 0x00000001009f8e75 QTextDocumentLayoutPrivate::layoutFrame(QTextFrame*, int, int, QFixed) + 661
21 QtGui 0x00000001009fb0b7 QTextDocumentLayoutPrivate::layoutFlow(QTextFrame::iterator, QTextLayoutStruct*, int, int, QFixed) + 5095
22 QtGui 0x00000001009f887a QTextDocumentLayoutPrivate::layoutFrame(QTextFrame*, int, int, QFixed, QFixed, QFixed) + 1418
23 QtGui 0x00000001009f8e75 QTextDocumentLayoutPrivate::layoutFrame(QTextFrame*, int, int, QFixed) + 661
24 QtGui 0x00000001009f90dc QTextDocumentLayout::doLayout(int, int, int) + 268
25 QtGui 0x00000001009f9927 QTextDocumentLayout::documentChanged(int, int, int) + 503
26 QtGui 0x00000001009c6e95 QTextDocument::markContentsDirty(int, int) + 69
27 QtGui 0x0000000100a18a59 QSyntaxHighlighterPrivate::applyFormatChanges() + 809
28 QtGui 0x0000000100a18c37 QSyntaxHighlighterPrivate::reformatBlock(QTextBlock const&) + 167
29 QtGui 0x0000000100a18da1 QSyntaxHighlighterPrivate::reformatBlocks(int, int, int) + 257
30 QtGui 0x0000000100a18f08 QSyntaxHighlighter::rehighlight() + 120
31 login 0x00000001000429d8 Highlighter::addcorrect(int, int) + 70
@As we see it happens in calss highlighter::addcorrect
@
void Highlighter::addcorrect(int line, int charact)
{
blockcounter=0;
ClearLetterColor(line,charact); //clear previous color of this character
correct.append(charact);
correctBlock.append(line);
this->rehighlight();
}
@my header file
@
#ifndef HIGHLIGHTER_H
#define HIGHLIGHTER_H
#include <QSyntaxHighlighter>
#include <QHash>
#include <QTextCharFormat>QT_BEGIN_NAMESPACE
class QTextDocument;
QT_END_NAMESPACE//! [0]
class Highlighter : public QSyntaxHighlighter
{
Q_OBJECTpublic:
Highlighter(QTextDocument *parent = 0);
void addmistake(int line, int charact);
void addcorrect(int line, int charact);
void addconcentrate(int line, int charact);
void ClearLetterColor(int line, int charactnumber);
void ClearAll();
int GetStrokesNumber(); // calculate number of mistakes and corrects
QList <int> mistakes; //mistake positions
QList <int> mistakesBlock; //block (line) number of each mistake
QList <int> concentrations;
QList <int> concentrationsBlock;
QList <int> correct;
QList <int> correctBlock;
struct Mistakes
{
int location;
int block;
};
protected:
void highlightBlock(const QString &text);
private:
void updatefn(int length);};
//! [0]#endif
@ -
my c++ file
@
#include <QtGui>
#include <QDebug>
#include "highlighter.h"
#include <QTextBlock>// Settings
QColor Focus_color = Qt::yellow; //focusQColor Mistake_color = Qt::red; //mistakes
QColor Mistake_color_background = Qt::white; //mistakes backgroundQColor Correct_color = Qt::green; //correct letter color
QColor Correct_color_background = Qt::gray; // correct color background
//int blockcounter;
QString doctext;//! [1]
Highlighter::Highlighter(QTextDocument *parent)
: QSyntaxHighlighter(parent)
{
blockcounter=0;
}
//! [1]void Highlighter::addcorrect(int line, int charact)
{
blockcounter=0;
//qDebug() << "addcorrect";
ClearLetterColor(line,charact); //clear previous color of this character// call this function to add reference to a mistake character in position pos correct.append(charact); correctBlock.append(line); this->rehighlight();
}
void Highlighter::highlightBlock(const QString &text)
{
if (!text.isEmpty())
{
//qDebug() << text << "linenumber=" << blockcounter;
updatefn(1);
blockcounter ++;
}
}//[2]
@