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. C++ QString to QByteArray Conversion
Qt 6.11 is out! See what's new in the release blog

C++ QString to QByteArray Conversion

Scheduled Pinned Locked Moved Solved General and Desktop
16 Posts 3 Posters 1.3k Views
  • 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.
  • R RuWex

    how to convert QString to QByteArrey?

    J.HilkJ Online
    J.HilkJ Online
    J.Hilk
    Moderators
    wrote on last edited by
    #2

    @RuWex

    https://doc.qt.io/qt-6/qstring.html#toLatin1


    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    R 1 Reply Last reply
    3
    • J.HilkJ J.Hilk

      @RuWex

      https://doc.qt.io/qt-6/qstring.html#toLatin1

      R Offline
      R Offline
      RuWex
      wrote on last edited by
      #3

      @J-Hilk
      what wrond did I do?

      jsulmJ 1 Reply Last reply
      0
      • R RuWex

        @J-Hilk
        what wrond did I do?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @RuWex said in C++ QString to QByteArray Conversion:

        what wrond did I do?

        How should we know?
        You asked a question and got a link to a method which does what you asked - did you read it?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        R 1 Reply Last reply
        0
        • jsulmJ jsulm

          @RuWex said in C++ QString to QByteArray Conversion:

          what wrond did I do?

          How should we know?
          You asked a question and got a link to a method which does what you asked - did you read it?

          R Offline
          R Offline
          RuWex
          wrote on last edited by
          #5

          @jsulm
          yes but @J-Hilk give me link :
          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

          Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121
          why:(

          jsulmJ 1 Reply Last reply
          0
          • R RuWex

            @jsulm
            yes but @J-Hilk give me link :
            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct

            Qt Needs YOUR vote: https://bugreports.qt.io/browse/QTQAINFRA-4121
            why:(

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @RuWex said in C++ QString to QByteArray Conversion:

            but @J-Hilk give me link

            He did not. This link is part of his signature...

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • R Offline
              R Offline
              RuWex
              wrote on last edited by
              #7

              its not work:

              mainwind->WriteSerial(line[i]::toLatin1());
              what wrong?
              
              jsulmJ 1 Reply Last reply
              0
              • R RuWex

                its not work:

                mainwind->WriteSerial(line[i]::toLatin1());
                what wrong?
                
                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #8

                @RuWex said in C++ QString to QByteArray Conversion:

                what wrong?

                Your code.
                toLating1() is not a static method...

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • R Offline
                  R Offline
                  RuWex
                  wrote on last edited by
                  #9

                  the error is:
                  4.PNG

                  jsulmJ 1 Reply Last reply
                  0
                  • R RuWex

                    the error is:
                    4.PNG

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @RuWex Please learn C++ basics!

                    mainwind->WriteSerial(line[i].toLatin1());
                    

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    R 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @RuWex Please learn C++ basics!

                      mainwind->WriteSerial(line[i].toLatin1());
                      
                      R Offline
                      R Offline
                      RuWex
                      wrote on last edited by
                      #11

                      @jsulm ou, I tried it before but its not work too:(

                      jsulmJ J.HilkJ 2 Replies Last reply
                      0
                      • R RuWex

                        @jsulm ou, I tried it before but its not work too:(

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @RuWex said in C++ QString to QByteArray Conversion:

                        I tried it before but its not work too:(

                        It would be really nice if you would post the error you get instead of simply saying that it did not work...

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        1
                        • R RuWex

                          @jsulm ou, I tried it before but its not work too:(

                          J.HilkJ Online
                          J.HilkJ Online
                          J.Hilk
                          Moderators
                          wrote on last edited by
                          #13

                          @RuWex give us more information than "it does not work too", please.


                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          R 1 Reply Last reply
                          0
                          • J.HilkJ J.Hilk

                            @RuWex give us more information than "it does not work too", please.

                            R Offline
                            R Offline
                            RuWex
                            wrote on last edited by RuWex
                            #14

                            @J-Hilk , @jsulm
                            ok
                            I understand the problem
                            the function toLatin1() is used to string
                            and here, because it is line[i]- its just one char, so it wants me to convert from char to QByteArray....

                            1 Reply Last reply
                            0
                            • R Offline
                              R Offline
                              RuWex
                              wrote on last edited by
                              #15

                              a little question...
                              I did it:

                              QString letter= (QString)line[i];
                                             mainwind->WriteSerial(letter.toLatin1());
                              

                              there is better way to do it?

                              J.HilkJ 1 Reply Last reply
                              0
                              • R RuWex

                                a little question...
                                I did it:

                                QString letter= (QString)line[i];
                                               mainwind->WriteSerial(letter.toLatin1());
                                

                                there is better way to do it?

                                J.HilkJ Online
                                J.HilkJ Online
                                J.Hilk
                                Moderators
                                wrote on last edited by
                                #16

                                @RuWex

                                    QSerialPort dev;
                                    char i{0x64};
                                    dev.write(&i, 1);
                                    dev.write(QByteArray::number(i));
                                

                                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                Q: What's that?
                                A: It's blue light.
                                Q: What does it do?
                                A: It turns blue.

                                1 Reply Last reply
                                1

                                • Login

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