[SOLVED] Crash in QRegExp::setPattern - Access violation



  • 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!



  • 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.



  • 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!!!!



  • If you pass around pointers and use it in different methods, make sure that the object survived. You may work on a dangling pointer.



  • 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!



  • Without seeing the actual code it's impossible to tell that.



  • 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!



  • 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).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.