Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved efficiently concatinate

    General and Desktop
    2
    3
    527
    Loading More Posts
    • 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.
    • D
      dit8 last edited by

      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?

      thanks!

      1 Reply Last reply Reply Quote 0
      • ?
        A Former User last edited by A Former User

        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.

        1 Reply Last reply Reply Quote 5
        • D
          dit8 last edited by

          thanks! thats great. I was not aware of that

          1 Reply Last reply Reply Quote 0
          • First post
            Last post