First here is my code:


//My_Highlightingrule.h
Qt Code:
  1. class My_Highlightingrule
  2. {
  3. public:
  4. My_Highlightingrule(QRegExp* ,QTextCharFormat* );
  5. QRegExp* getPattern();
  6. QTextCharFormat* getFormat();
  7.  
  8.  
  9. private:
  10. QRegExp* pattern;
  11. QTextCharFormat* format;
  12. };
To copy to clipboard, switch view to plain text mode 


//My_Highlightingrule_KeyWords.h
Qt Code:
  1. class My_Highlightingrule_KeyWords : public QList<My_Highlightingrule*>
  2. {
  3. public:
  4. My_Highlightingrule_KeyWords();
  5. };
To copy to clipboard, switch view to plain text mode 

//My_Highlightingrule_KeyWords.cpp
Qt Code:
  1. #include "my_highlightingrule_keyWords.h"
  2.  
  3.  
  4. My_Highlightingrule_KeyWords::My_Highlightingrule_KeyWords()
  5. {
  6. const int MAX = 51;
  7. std::string keyWords[MAX] = {"abstract", "continue", "for", "new",
  8. "switch", "assert", "default", "goto",
  9. "package", "synchronized", "boolean",
  10. "do", "if", "private", "this", "break",
  11. "double", "implements", "protected",
  12. "throw", "byte", "else", "import",
  13. "public", "throws", "case", "enum",
  14. "instanceof", "return", "transient",
  15. "catch", "extends", "int", "short",
  16. "try", "char", "final", "interface",
  17. "static", "void", "class", "finally",
  18. "long", "strictfp", "volatile", "const",
  19. "float", "native", "super", "while"};
  20.  
  21. QBrush brush(QColor(255,0,0,127));
  22. format.setForeground(brush);
  23.  
  24. QRegExp *pattern;
  25.  
  26. for(int i = 0; i < MAX; i++)
  27. {
  28. pattern = new QRegExp(QString("\\b%1\\b").arg(keyWords[i].c_str()));
  29. My_Highlightingrule *rule = new My_Highlightingrule(pattern,&format);
  30. insert(i,rule);
  31. }
  32.  
  33. std::cout << at(49)->getPattern()->pattern()->toStdString() << std::endl; //NO SEGMENTATION FAULT
  34.  
  35. delete(pattern);
  36. }
To copy to clipboard, switch view to plain text mode 



//My highlight function...does not highlight now

Qt Code:
  1. void My_CppSyntaxHighlighter::highlight(const QString & text)
  2. {
  3. QList<My_Highlightingrule*> rules;
  4. My_Highlightingrule_KeyWords keyWords = y_Highlightingrule_KeyWords();
  5.  
  6. std::cout << keyWords.at(49)->getPattern()->pattern()->toStdString() << std::endl; //SEGMENTATION FAULT
  7.  
  8.  
  9. rules += keyWords; //KeyWords, and so on
  10. }
To copy to clipboard, switch view to plain text mode 




Ahhm, as you see I have not inserted the #includes and so on.
What I want:
I want a Class My_CppHIghlightingrules which derive from My_SyntaxHighlighting (Is only a Abstract class with a member highlight(const QString&). The function highlight(const QString& text) in My_CppHighlightingrules should add some Highlightingrules (e.g.: My_Highlighting_KeyWords) and then go with a loop through all rules and return the new text.
Problem:
My Problem is this. When I create an object of My_Highlightingrule_Keywords in highlight(const QString&) and I want the last Keyword "while" (see My_Highlightingrule_Keywords() ) then it gives me an Segmentation fault. But when I print the last Keyword "while" in My_Highlightingrule_KeyWords (see My_Highlighting_Keywords() ) then it gives me no Segmentation fault. WHY????? I don't understand it. Please help me.