efficiently concatinate

  • say I have code looking like:
    QByteArray param = "two";
    QByteArray newStr = "one";
    newStr.append(param).append(" three");

    on each append I suppose there is a reallocation taking place. is there a solution taht enables be to have a single alloaction.

    reserve seems like uncompurtable option.
    I know of QStringBuilder - is there an equivalent for QByteArray?


  • Hi! You're lucky because QStringBuilder already supports QByteArray :-)

    #include <QStringBuilder>
    #include <QDebug>
    // ...
    QByteArray  say("say");
    QByteArray  hello("hello");
    QByteArray  world("world");
    QByteArray  message =  say % hello % world;
    qDebug() << message;

    See also String concatenation with QStringBuilder by Olivier Goffart.

  • thanks! thats great. I was not aware of that

Log in to reply

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