i have a class derived from QPlainTextEdit.
i added a member of type QList<[my struct]> to it. since that, the program fails to exit properly ( exit with code -1073741819 after 10-15 seconds of hold ) in debug mode.
any idea why?
Printable View
i have a class derived from QPlainTextEdit.
i added a member of type QList<[my struct]> to it. since that, the program fails to exit properly ( exit with code -1073741819 after 10-15 seconds of hold ) in debug mode.
any idea why?
Post the code of your class please.
It's an access violation. Maybe you're trying to access an item in the list that doesn't exist (like in going beyond the item count of the list)
the thing is, it only happens in debug runs when i quit the program; release quits fine- i just cant find any logic to that.
the class is quite big, that was the reason i didn't post it in the first place. the structs involvement is somewhat minimal.
its somewhat disorganized since its still work in progress Frankenstein test subject..
i tried to cut the code down to only where the new list is relevant, which is still not small
the list i was refering to is "QList<folder> folders;"
it holds QChars for code folding (kinda)
Code:
#ifndef CODEEDITOR_H #define CODEEDITOR_H #include<QPlainTextEdit> #include<QObject> #include<QTextBlockUserData> #include<QtGui> class Highlighter; class LineNumberArea; struct folder { QChar open; QChar close; }; //-------------------------------------- class CodeEditor : public QPlainTextEdit { Q_OBJECT public: int lineNumberAreaWidth(); Highlighter* highlighter() const {return mHighligher;} private: void bracingEvent(); void homePressedEvent(); void tabPressedEvent(bool shiftPressed); int findTwinBehind( folder req ); int findTwinAhead( folder req ); void popCompleter(); void informCompleter(); private slots: void updateLineNumberAreaWidth(int newBlockCount); void makeExtraSelections(); void insertCompletion(const QString& completion); private: QWidget* lineNumberArea; Highlighter* mHighligher; QCompleter* mCompleter; QList<folder> folders; }; //-------------------------------------- #endif // CODEEDITOR_H
Code:
#include "codeEditor.h" #include"highlighter.h" { QStringList completionList; completionList << "for" << "while" << "do" << "if" << "else"; lineNumberArea = new LineNumberArea(this); mHighligher = new Highlighter(this->document()); mCompleter->setWidget(this); connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int))); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(makeExtraSelections())); setStyleSheet("QPlainTextEdit { selection-background-color: darkgray }"); updateLineNumberAreaWidth(0); folder fold; fold.open = '{'; fold.close = '}'; folders.append(fold); fold.open = '('; fold.close = ')'; folders.append(fold); fold.open = '['; fold.close = ']'; folders.append(fold); } // ::::::: GENERAL METHODS ::::::: //--------------------------------------------------------------------------- void CodeEditor::makeExtraSelections() { QList<QTextEdit::ExtraSelection> extraSelections; // make current line glow yellow ( not related to the syntax highlighter ) //----------------------------------------------------------- selection->cursor = textCursor(); selection->cursor.clearSelection(); extraSelections.append(*selection); //----------------------------------------------------------- // highlight parenthesis under cursor and its twin (behind or ahead) //----------------------------------------------------------- foreach( folder cur_fold, folders ) { if( document()->characterAt(textCursor().position()-1) ==cur_fold.close) { selection->cursor = textCursor(); extraSelections.append(*selection); selection->cursor = textCursor(); selection->cursor.setPosition(findTwinBehind(cur_fold)+1); extraSelections.append(*selection); } if( document()->characterAt(textCursor().position()-1) ==cur_fold.open) { selection->cursor = textCursor(); extraSelections.append(*selection); selection->cursor = textCursor(); selection->cursor.setPosition(findTwinAhead(cur_fold)-1); extraSelections.append(*selection); } } //----------------------------------------------------------- setExtraSelections(extraSelections); } { ......... //replace comment character with '@' .......... } // methods for finding matching pairs of expressions (parenthesis) int CodeEditor::findTwinBehind( folder req ) { int i = cleaned.size()-2; int braceBalance = -1; while( i>0 && braceBalance<0 ) { if(cleaned.at(i)==req.close) braceBalance-=1; if(cleaned.at(i)==req.open) braceBalance+=1; i--; } return i; } int CodeEditor::findTwinAhead( folder req ) { int i = 0; int braceBalance = 1; while( i<cleaned.size() && braceBalance>0 ) { if(cleaned.at(i)==req.close) braceBalance-=1; if(cleaned.at(i)==req.open) braceBalance+=1; i++; } return i+textCursor().position(); } { setReadOnly(false); makeExtraSelections(); QPlainTextEdit::focusInEvent(e); } { setReadOnly(true); QList<QTextEdit::ExtraSelection> extraSelections; setExtraSelections(extraSelections); QPlainTextEdit::focusOutEvent(e); }
lets talk more basic - even when it is not referenced anywhere in the code, its very existence seems to disallow proper quitting exclusively in debug. what could be causing this?
i know i sound vague, but there isn't really much to it; if its there it crashes at exit in debug, if not it doesn't..
Post a small compilable example that causes the problem.
switched from MinGW to MSVC compilation; seems to have resolved the issue..
I have seen something like this before, very hard to find. I think what helped was using .value(var) instead of .at(var), it's null pointer safe.