Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Crash in QRegExp::setPattern - Access violation
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 3.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jensen82J Offline
    jensen82J Offline
    jensen82
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      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.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • jensen82J Offline
        jensen82J Offline
        jensen82
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

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

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • jensen82J Offline
            jensen82J Offline
            jensen82
            wrote on last edited by
            #5

            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!

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on last edited by
              #6

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

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • jensen82J Offline
                jensen82J Offline
                jensen82
                wrote on last edited by
                #7

                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!

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

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

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved