concatenate two QStrings

  • Hello, i have new problem.I have read a lot of threads but all the suggestions didn't work up to now.
    I have a hex file with "10 F9 F8 05" I want to combine " 10 F9" to "10F9"
    here is part of my code with outcommented tries.I have always "1000"

      case 1 :    high.append(hexMatch.capturedRef(0));
                                                    case 2:  {  low.append(hexMatch.capturedRef(0));
                                                                 qDebug()<<"low=="<<low; //=F9
                                                                 highlow=high ;
                                                                 highlow += low;
                                                         //             highlow=*high + *low;  
                                                        //              highlow.append(low);
                                                        //              highlow=QString("%1 %2").arg(high).arg(low);
                                                                qDebug()<<"highlow=="<<highlow; // should be 10F9 is 1000

    who can help?

  • Qt Champions 2017

    What types are low and high ?

  • Both are QString,they are definedin the .h file. But I have already realized that the append is bad here.It has to be a new entry every time.With append i get a "vector".
    All this is running in a while loop.

  • Qt Champions 2017

    is the input always just "10 F9 F8 05"
    or more like
    10 F9 F8 0510 F9 F8 0510 F9 F8 0510 F9 F8 0510 F9 F8 0510 F9 F8 05

  • it is the long type.My code was ok up to now. I had read each value as single .But I need to concatenate two values to one and then transver it to dec.
    Meanwhile I changed my code this way

                                                    case 1 :   high +=hexMatch.capturedRef(0);
                                                    case 2:  {  low +=(hexMatch.capturedRef(0));
                                                                 qDebug()<<"low=="<<low; //=F9
    ``but then it recognices only the low value.`

  • @Leopold
    I really don't understand what you are saying!
    Twice in a row you are using the same hexMatch.capturedRef(0);; hexmatch does not change, and they are both using capturedRef(0). You say they give different results (10 and F9), but as it stands it does not look like they can.... So what is your actual code if it's not what you show?

  • Hi JonB
    this is my actual code

    if (line_count>3) // read line from line 4
    							x.append(tick); // this will be x-line in a plot
    							int h=0;
    							const QRegularExpression eingangExp(QStringLiteral("^\\s*([0-9a-fA-F]{2}):"));
                                const QRegularExpression hexRegExp(QStringLiteral("[0-9a-fA-F]{2}(?!:)"));
                                const QRegularExpressionMatch eingangMatch = eingangExp.match(line);
                                const QRegularExpressionMatch hexMatch;
                                        { // Eingang==("80:")
                                            qDebug() << eingangMatch;
                                            for(QRegularExpressionMatchIterator i = hexRegExp.globalMatch(line);
                                                {  //qDebug()<< "h="<<h;
    												const QRegularExpressionMatch hexMatch =;
    												qDebug() << hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16);
                                                    case 1 :  high="";
                                                    case 2:  {low="";
                                                                qDebug()<<"high2=="<<highlow; // should be 10F9 is 1000
                                                  //    case 1 : y56.append(hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16)); break;//Dataframe
                                                    //    case 2 : y1.append(hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16)); break;//engine speed
                                                      //          y54.append(hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16)); break;//engine speed
                                                        case 3 :  { qreal t=hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16);//coolant temp
                                                                   qreal u=(t-32)*55556/100000;// calculate celsius from fahrenheit
                                                                   y2.append(u); break;}//engine speed raw
                                                        case 4 : {qreal t=hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16);//coolant temp
                                                                  qreal u=(t-32)*55556/100000;
                                                                  y3.append(u); break;}//water temp
                                                        case 5 : {qreal t=hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16);//coolant temp
                                                                  qreal u=(t-32)*55556/100000;
                                                                  y4.append(u); break;}//ambienttemp
                                                        case 6 : {qreal t=hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16);//coolant temp
                                                                  qreal u=(t-32)*55556/100000;
                                                                  y5.append(u); break;}//intake air
                                                        case 7 : y6.append(hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16)); break;//fuel temp
                                                        case 8 : y7.append(hexMatch.capturedRef(0).toUInt(Q_NULLPTR,16)); break;//Map

    and you are right , low is filled with the value from case 1 too.
    This is the line to be read:"80: 1C 00 9F 41 FF 43 41 5C 71 2B 00 and so on

  • @Leopold

    and you are right , low is filled with the value from case 1 too.

    It's very naughty to tell us that qDebug()/your code shows you something, and when I challenge you you now say it returns something else! :)

    I don't claim to understand your whole code or your reg exp, but:


    Capture 0 is the match for the first ( ... ) in your reg exp. For you, that's the (?!:), whatever that is. But don't you want the two hex digits from the reg exp? So something more like:


    (I have inserted parentheses around the two digits match)?

  • @JonB
    sorry when I gave you wrong information.I would like to paste and copy the debug as well but its not posible out of the creator and picture is very difficult.

    I have added the parentheses but there is no change.

  • @Leopold
    OK, forget what I said earlier . Here are your (two) problems:

    1. So far as I can spot: Your h starts off as 0. You only increment it at the end of each time through the loop. So e.g. first time it does not match any of the case clauses. What's going on with that?

    2. You do not have a break; statement at the end of case 1:. So it continues straight into the case 2:. With exactly the same hexMatch.capturedRef(0) value. What is going on with that?

    Sort your code out sensibly and have another go!

  • hi JonB and mrJJ
    now it is working i had two mistakes.
    First : the break was missing after case 1
    second: had the wrong y ```
    case 1 : high="";
    qDebug()<<"high=="<<high;break;// this break was missing
    case 2: {low="";
    y1.append(highlow.toUInt(Q_NULLPTR,16));//this y was wrong, former y2

    thank you for your help.

  • @Leopold
    Also, you kept saying:

    I have always "1000"

    Am I right in saying the qDebug() output was actually 1010 instead? Because if you had said that it would have been much quicker to diagnose!

  • @JonB
    Hi JonB
    you gave answer at thesame time when I did.
    I realized the break too. Sometimes the code is too near to the eyes. :-)
    With the h, it's by intention.
    This is the line to be read in
    This is the line to be read:"80: 1C 00 9F 41 FF 43 41 5C 71 2B 00 and so on
    and I want to start it after the 1C.
    Thank you again.

Log in to reply

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