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] Problem with QRegularExpression
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Problem with QRegularExpression

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.4k Views 1 Watching
  • 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.
  • I Offline
    I Offline
    igorland
    wrote on last edited by
    #1

    Hello. I have a problem with regex. The following function crashes my program:

    [code]
    QString Metar::getTemperature()
    {

    QString temp;
    QString metarReport = "CYOW 171900Z 33329G45MPS 15SM SCT050 24/M13 A3013 RMK CU3 SLP251 DENSITY ALT 1200FT";
    
    // If Metar report has not been downloaded properly
    if (metarReport == "N/A")
    {
        temperature = "N/A";
    }
    
    else
    {
        QRegularExpression rx("(^|\\s)M?\\d+/M?\\d+($|\\s)");
        QRegularExpressionMatch match = rx.match(metarReport);
        if (match.hasMatch())
        {
            temp = match.captured(1);
        }
    
    
        // The resulting string has space in the beginning. We remove the space.
        temp.replace(" ","");
    
        // If temperature is below zero we need to replace "M" with "-"
        temp.replace('M', '-' );
    
        // We want only the first part of the string. The second part is dew.
        QStringList tokens = temp.split("/");
        temperature = tokens[1];
    }
    
    return temperature;
    

    }
    [/code]

    It should return 24.
    I tried it with QRegEx -- same problem.

    Thanks for your help!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      Hi,
      Are you sure that the length of your tokens is greater than or equal to 2 ?

      1 Reply Last reply
      0
      • I Offline
        I Offline
        igorland
        wrote on last edited by
        #3

        Hi,

        I changed to

        temp = match.captured(0);

        I do not have this problem now. No crash.

        Thanks!

        Igor

        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