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 can I see and storage the data from device in QT?
Qt 6.11 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.
  • dheerendraD dheerendra

    only mSerialport->setPortName("/dev/ttyUSB0") this may be sufficient.

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

    @dheerendra
    Can not I solve the problem without changing the "mSerialport->setPortName("/dev/ttyUSB0")" ? I do not think I can change it.

    jsulmJ 1 Reply Last reply
    -1
    • S segtteee

      @dheerendra
      Can not I solve the problem without changing the "mSerialport->setPortName("/dev/ttyUSB0")" ? I do not think I can change it.

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

      @segtteee Why can't you change it?

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

      S 1 Reply Last reply
      1
      • jsulmJ jsulm

        @segtteee Why can't you change it?

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

        @jsulm
        I can write code by specifying one port, but I can not write one after choosing multiple ports...i am a beginner sorry..

        jsulmJ 1 Reply Last reply
        0
        • S segtteee

          @jsulm
          I can write code by specifying one port, but I can not write one after choosing multiple ports...i am a beginner sorry..

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

          @segtteee Then you should learn how to do it.
          Where does the user select the port? Is it a QComboBox? Something else?

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

          S 1 Reply Last reply
          2
          • jsulmJ jsulm

            @segtteee Then you should learn how to do it.
            Where does the user select the port? Is it a QComboBox? Something else?

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

            @jsulm
            it is combobox

            jsulmJ 1 Reply Last reply
            0
            • S segtteee

              @jsulm
              it is combobox

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

              @segtteee Then just go to the documentation: http://doc.qt.io/qt-5/qcombobox.html#currentText-prop
              Change

              mSerialport->setPortName("/dev/ttyUSB0");
              

              to

              mSerialport->setPortName(ui->comboBox->currentText()); // Change the name of the combobox if it's called differently in your code
              

              Really easy, isn't it? :-)

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

              S 1 Reply Last reply
              2
              • jsulmJ jsulm

                @segtteee Then just go to the documentation: http://doc.qt.io/qt-5/qcombobox.html#currentText-prop
                Change

                mSerialport->setPortName("/dev/ttyUSB0");
                

                to

                mSerialport->setPortName(ui->comboBox->currentText()); // Change the name of the combobox if it's called differently in your code
                

                Really easy, isn't it? :-)

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

                @jsulm
                I modified the port name as you told me. I also changed baudrate and databite equally, but here I get an error.
                "" no matching function for call to ‘QSerialPort::setBaudRate(QString)’
                mSerialport->setBaudRate(ui->comboBox_baudrate->currentText()); ""
                Can I change only the port name?

                jsulmJ 1 Reply Last reply
                0
                • K Offline
                  K Offline
                  Kicer86
                  wrote on last edited by
                  #12

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

                  Can I change only the port name?

                  If you want to hardcode all values in code, why do you put comboboxes in ui?

                  1 Reply Last reply
                  0
                  • S segtteee

                    @jsulm
                    I modified the port name as you told me. I also changed baudrate and databite equally, but here I get an error.
                    "" no matching function for call to ‘QSerialPort::setBaudRate(QString)’
                    mSerialport->setBaudRate(ui->comboBox_baudrate->currentText()); ""
                    Can I change only the port name?

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

                    @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());
                    

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

                    S 1 Reply Last reply
                    2
                    • 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

                                          • Login

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