[SOLVED] Crash in QRegExp::setPattern - Access violation
-
wrote on 29 Nov 2011, 19:51 last edited by
Hi!
I'm using a QRegExp to parse data and get an access violation after setting the 2nd setPattern. The Regex is pointer..
Example Code:
@
regExp = new QRegExp("", Qt::CaseInsensitive, QRegExp::RegExp2);regExp->setPattern("^pokerstars\s+(game|spiel)\s+"); // set the pattern
regExp->exactMatch(*input); // parse subject// some code, then i use setPattern again
regExp->setPattern("^\#([a-zA-Z0-9]+)\:\s"); // set the pattern <-- CRASH
regExp->exactMatch(*input); // parse subject@
A screenshot is here:
http://img41.imageshack.us/img41/4937/screennmm.jpg
d is not accesable...but why? What's wrong here?
Thank you for your help!
-
wrote on 29 Nov 2011, 21:48 last edited by
The snippet works for me. Something most go wrong in the middle. Can you provide a small, complete example so that we can reproduce the error.
Some side notes:
It seems that you use a heap allocated regexp, do you have any reasons for that? The class is lightweight and usually used as stack object.The string you match against seems to be heap allocated too, this is not necessary. With implicit sharing, QString can be passed along without big ovehead. If you need to pass an object that needs to be manipulated, pass a reference.
-
wrote on 30 Nov 2011, 18:55 last edited by
Hi!
Thank you for your answer. I tried QRegExp as a stack object and get the same error. But there's a bit of information i did not provide. I use regExp::setPattern in 2 different functions, but I'm sure that this isn't the problem here.
You gave me some information to work with, but now i want to try solve the problem myself and will inform you about my success or no success. Like learning by doing... :-)
Thank you very much!!!!
-
wrote on 1 Dec 2011, 12:01 last edited by
If you pass around pointers and use it in different methods, make sure that the object survived. You may work on a dangling pointer.
-
wrote on 1 Dec 2011, 18:06 last edited by
Hi!
OK, now i created the regex on stack in 2 different methods and it works. Why can't i use it as a class member and get an access violation? It's a derived class.
Can you provide some infos?
Thank you!
-
wrote on 1 Dec 2011, 18:49 last edited by
Without seeing the actual code it's impossible to tell that.
-
wrote on 1 Dec 2011, 19:30 last edited by
Yes...found the error. Stupid mistake...created the regex in the base-class, but that must be done in the derived class. Very stupid. Thank you for your help!
-
wrote on 2 Dec 2011, 00:10 last edited by
You're welcome. Glad to know it works now.
You might add "[Solved]" to the topic (just hit the edit button of the very first post in the thread and adjust the title).
8/8