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. How enter different QString in one QByteArray

How enter different QString in one QByteArray

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 1.1k Views 2 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.
  • J Offline
    J Offline
    Jeronimo
    wrote on last edited by Jeronimo
    #1

    Hi for example if i have different qstring like:
    QString name = "myname"
    QString game = "mygame"
    Etc..
    In one QByteArray???

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      One way:

      QByteArray byteArray = (name + game).toLatin1();
      

      Or directly make name and game QByteArrays.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • qtpizarroQ Offline
        qtpizarroQ Offline
        qtpizarro
        wrote on last edited by
        #3

        Other way is

        QByteArray myByteArray;
        myByteArray.append(name);
        myByteArray.append(game);
        
        or 
        
        QByteArray myByteArray;
        myByteArray.append(name+game);
        
        
        
        1 Reply Last reply
        1
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Or:

          QString n = "one";
          QString g = "two";
          QByteArray ba;
          {
            QTextStream ts(&ba, QIODevice::Append);
            ts << n << g;
          }
          
          1 Reply Last reply
          2

          • Login

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