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. Is that possible to put QSting in to QBytearray?
Qt 6.11 is out! See what's new in the release blog

Is that possible to put QSting in to QBytearray?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 788 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by victor wang
    #1

    Hi All,
    I'm using qt5.5 and Linux+QT for my OS system.
    This is my program.

    QString addr = "55:55:55:55:55:55";
    QByteArray pair("pair "+addr+"\n");
    

    Can I just put in like this?
    If can't then how can I do something like this?

    Thanks in Advanced!

    raven-worxR 1 Reply Last reply
    0
    • V victor wang

      Hi All,
      I'm using qt5.5 and Linux+QT for my OS system.
      This is my program.

      QString addr = "55:55:55:55:55:55";
      QByteArray pair("pair "+addr+"\n");
      

      Can I just put in like this?
      If can't then how can I do something like this?

      Thanks in Advanced!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @victor-wang said in Is that possible to put QSting in to QBytearray?:

      QString addr = "55:55:55:55:55:55";
      QBytearray pair = QByteArray("pair ")+addr.toUtf8()+QByteArray("\n");
      

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      5
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by VRonin
        #3

        The Absolute Minimum Every Software Developer Absolutely, Positively Must Know About Unicode and Character Sets (No Excuses!)

        Given all your string is ASCII-representable: "pair "+addr.toLatin1()+"\n"

        EDIT:
        The answer is @raven-worx is also correct, the only note is that I'd use QByteArrayLiteral("pair ") instead of QByteArray("pair ") as some compilers can optimise that better

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        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