Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How can I see and storage the data from device in QT?
Qt 6.12 LTS is out! See what's new in the release blog

How can I see and storage the data from device in QT?

Scheduled Pinned Locked Moved Unsolved General and Desktop
28 Posts 5 Posters 10.2k 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.
  • jsulmJ jsulm

    @segtteee See the documentation: http://doc.qt.io/qt-5/qserialport.html#baudRate-prop
    setBaudRate() takes an integer not a string.
    See again documentation to find out how to convert a string to an integer: http://doc.qt.io/qt-5/qstring.html#toInt

    mSerialport->setBaudRate(ui->comboBox_baudrate->currentText().toInt());
    
    S Offline
    S Offline
    segtteee
    wrote on last edited by
    #14

    @jsulm
    I understand that the port name is a string, and baudrate is a number, so toint is an integer, but databits is a number, why not toint? And paritybits is a character, but it should not be used.

    jsulmJ 1 Reply Last reply
    0
    • S segtteee

      @jsulm
      I understand that the port name is a string, and baudrate is a number, so toint is an integer, but databits is a number, why not toint? And paritybits is a character, but it should not be used.

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

      @segtteee said in How can I see and storage the data from device in QT?:

      databits is a number, why not toint?

      I don't understand. If it is a number then convert it to a number like baud rate.

      "And paritybits is a character, but it should not be used" - don't know what you mean. If it should not be used then don't use it.

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

      S 1 Reply Last reply
      2
      • jsulmJ jsulm

        @segtteee said in How can I see and storage the data from device in QT?:

        databits is a number, why not toint?

        I don't understand. If it is a number then convert it to a number like baud rate.

        "And paritybits is a character, but it should not be used" - don't know what you mean. If it should not be used then don't use it.

        S Offline
        S Offline
        segtteee
        wrote on last edited by
        #16

        @jsulm
        it mean
        port name = string so currentText()
        baud rate = integer so currentText().toint()

        data bits = integer so ??
        Is not the toint() correct for the data bits? but error occured

        jsulmJ 1 Reply Last reply
        0
        • S segtteee

          @jsulm
          it mean
          port name = string so currentText()
          baud rate = integer so currentText().toint()

          data bits = integer so ??
          Is not the toint() correct for the data bits? but error occured

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

          @segtteee Could you please show real code and the error message?
          DataBits is an enum, so you can do something like:

          DataBits dataBits;
          if (ui->dataBits.currentText() == "Data5")
              dataBits = DataBits::Data5;
          else if ...
          

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

          S 1 Reply Last reply
          2
          • jsulmJ jsulm

            @segtteee Could you please show real code and the error message?
            DataBits is an enum, so you can do something like:

            DataBits dataBits;
            if (ui->dataBits.currentText() == "Data5")
                dataBits = DataBits::Data5;
            else if ...
            
            S Offline
            S Offline
            segtteee
            wrote on last edited by
            #18

            @jsulm
            alt text
            alt text

            jsulmJ 1 Reply Last reply
            0
            • S segtteee

              @jsulm
              alt text
              alt text

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

              @segtteee See my previous post

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

              S 1 Reply Last reply
              1
              • jsulmJ jsulm

                @segtteee See my previous post

                S Offline
                S Offline
                segtteee
                wrote on last edited by
                #20

                @jsulm

                if (ui->comboBox_databits->currentText() == "Data8")
                mSerialport->setDataBits("Data8") ;
                error occured ..

                jsulmJ 1 Reply Last reply
                0
                • S segtteee

                  @jsulm

                  if (ui->comboBox_databits->currentText() == "Data8")
                  mSerialport->setDataBits("Data8") ;
                  error occured ..

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

                  @segtteee First, please read what I write more carefully, second if you get an error please post it.
                  This is wrong:

                  if (ui->comboBox_databits->currentText() == "Data8")
                      mSerialport->setDataBits("Data8") ;
                  

                  As I wrote above setDataBits takes an enum not a string - why do you try to pass a string?
                  You should really read documentation.
                  Here again the code I already posted before:

                  DataBits dataBits;
                  if (ui->dataBits.currentText() == "Data5")
                      dataBits = DataBits::Data5;
                  else if ..
                  ...
                  // new
                  mSerialport->setDataBits(dataBits) ;
                  

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

                  S 1 Reply Last reply
                  1
                  • jsulmJ jsulm

                    @segtteee First, please read what I write more carefully, second if you get an error please post it.
                    This is wrong:

                    if (ui->comboBox_databits->currentText() == "Data8")
                        mSerialport->setDataBits("Data8") ;
                    

                    As I wrote above setDataBits takes an enum not a string - why do you try to pass a string?
                    You should really read documentation.
                    Here again the code I already posted before:

                    DataBits dataBits;
                    if (ui->dataBits.currentText() == "Data5")
                        dataBits = DataBits::Data5;
                    else if ..
                    ...
                    // new
                    mSerialport->setDataBits(dataBits) ;
                    
                    S Offline
                    S Offline
                    segtteee
                    wrote on last edited by
                    #22

                    @jsulm
                    "DataBits dataBits; " is not written . what mean "DataBits dataBits;"?
                    I read the docummets and see "QSerialPort::Data8"
                    so I write
                    "if (ui->comboBox_databits->currentText() == "Data8")
                    mSerialport(QSerialPort::Data8); "
                    but error occured

                    jsulmJ J.HilkJ 2 Replies Last reply
                    -1
                    • S segtteee

                      @jsulm
                      "DataBits dataBits; " is not written . what mean "DataBits dataBits;"?
                      I read the docummets and see "QSerialPort::Data8"
                      so I write
                      "if (ui->comboBox_databits->currentText() == "Data8")
                      mSerialport(QSerialPort::Data8); "
                      but error occured

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

                      @segtteee Again: what error?

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

                      S 1 Reply Last reply
                      1
                      • S segtteee

                        @jsulm
                        "DataBits dataBits; " is not written . what mean "DataBits dataBits;"?
                        I read the docummets and see "QSerialPort::Data8"
                        so I write
                        "if (ui->comboBox_databits->currentText() == "Data8")
                        mSerialport(QSerialPort::Data8); "
                        but error occured

                        J.HilkJ Offline
                        J.HilkJ Offline
                        J.Hilk
                        Moderators
                        wrote on last edited by
                        #24

                        @segtteee said in How can I see and storage the data from device in QT?:

                        mSerialport(QSerialPort::Data8);

                        I'm pretty sure thats not a valid constructor of QSerialPort and I'm even more sure that not want you want to do in this case, anyway.


                        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
                        • jsulmJ jsulm

                          @segtteee Again: what error?

                          S Offline
                          S Offline
                          segtteee
                          wrote on last edited by
                          #25

                          @jsulm
                          if alt text
                          "‘DataBits’ was not declared in this scope
                          DataBits dataBits; " error occured

                          if
                          alt text
                          "expression cannot be used as a function
                          mSerialport(QSerialPort::Data8); " error occured
                          ^

                          jsulmJ 1 Reply Last reply
                          0
                          • S segtteee

                            @jsulm
                            if alt text
                            "‘DataBits’ was not declared in this scope
                            DataBits dataBits; " error occured

                            if
                            alt text
                            "expression cannot be used as a function
                            mSerialport(QSerialPort::Data8); " error occured
                            ^

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

                            @segtteee Change

                            DataBits dataBits;
                            

                            to

                            QSerialPort::DataBits dataBits;
                            

                            This does not make any sense:

                            mSerialport(QSerialPort::Data8);
                            

                            must be

                            mSerialport->setDataBits(QSerialPort::Data8);
                            

                            Also if you directly call mSerialport->setDataBits(QSerialPort::Data8); inside if then you do not need dataBits variable...

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

                            S 1 Reply Last reply
                            3
                            • jsulmJ jsulm

                              @segtteee Change

                              DataBits dataBits;
                              

                              to

                              QSerialPort::DataBits dataBits;
                              

                              This does not make any sense:

                              mSerialport(QSerialPort::Data8);
                              

                              must be

                              mSerialport->setDataBits(QSerialPort::Data8);
                              

                              Also if you directly call mSerialport->setDataBits(QSerialPort::Data8); inside if then you do not need dataBits variable...

                              S Offline
                              S Offline
                              segtteee
                              wrote on last edited by
                              #27

                              @jsulm
                              if (ui->comboBox_databits->currentText() == "Data8")
                              mSerialport->setDataBits(QSerialPort::Data8);
                              else if (ui->comboBox_databits->currentText() == "Data7")
                              mSerialport->setDataBits(QSerialPort::Data7);
                              else if (ui->comboBox_databits->currentText() == "Data6")
                              mSerialport->setDataBits(QSerialPort::Data6);
                              I write the above code , error not occured .
                              Parity,Stopbits,flowcontrol , Can I do the same with them?

                              jsulmJ 1 Reply Last reply
                              0
                              • S segtteee

                                @jsulm
                                if (ui->comboBox_databits->currentText() == "Data8")
                                mSerialport->setDataBits(QSerialPort::Data8);
                                else if (ui->comboBox_databits->currentText() == "Data7")
                                mSerialport->setDataBits(QSerialPort::Data7);
                                else if (ui->comboBox_databits->currentText() == "Data6")
                                mSerialport->setDataBits(QSerialPort::Data6);
                                I write the above code , error not occured .
                                Parity,Stopbits,flowcontrol , Can I do the same with them?

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

                                @segtteee Yes you can

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

                                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
                                • Unsolved