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. COM+QCustomPlot problem is QStringList[].toDouble()
Forum Updated to NodeBB v4.3 + New Features

COM+QCustomPlot problem is QStringList[].toDouble()

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 343 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.
  • B Offline
    B Offline
    banhmisua
    wrote on last edited by
    #1

    hi. i am a newbie in QT. I need ur help to solve my problem.
    my problem is : i can't read value of "giatri" when i use systax: giatri=QString(bufferSplit[0]).toDouble();
    i still read bufferSpilt[0].
    here my code:
    void MainWindow::serialport_read()
    {

    QStringList bufferSplit = data_string.split("\n");
    if(bufferSplit.length()<2)
    {
        buffer=serialPort->readAll();
        data_string+=QString::fromStdString(buffer.toStdString());
    }
    else
    {
        ui->pteReceive->insertPlainText(bufferSplit[0]);
        // show data read ok! eg: 96,80,94
    
        giatri=QString(bufferSplit[0]).toDouble();// not working
        //giatri++;
        time=time+1;
        addPoint(time,giatri);
        plot();
        data_string="";
    }
    

    }
    and my result :
    16_5_2022.png
    thank ur help!

    jsulmJ 1 Reply Last reply
    0
    • B banhmisua

      hi. i am a newbie in QT. I need ur help to solve my problem.
      my problem is : i can't read value of "giatri" when i use systax: giatri=QString(bufferSplit[0]).toDouble();
      i still read bufferSpilt[0].
      here my code:
      void MainWindow::serialport_read()
      {

      QStringList bufferSplit = data_string.split("\n");
      if(bufferSplit.length()<2)
      {
          buffer=serialPort->readAll();
          data_string+=QString::fromStdString(buffer.toStdString());
      }
      else
      {
          ui->pteReceive->insertPlainText(bufferSplit[0]);
          // show data read ok! eg: 96,80,94
      
          giatri=QString(bufferSplit[0]).toDouble();// not working
          //giatri++;
          time=time+1;
          addPoint(time,giatri);
          plot();
          data_string="";
      }
      

      }
      and my result :
      16_5_2022.png
      thank ur help!

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

      @banhmisua said in COM+QCustomPlot problem is QStringList[].toDouble():

      my problem is : i can't read value of "giatri" when i use systax: giatri=QString(bufferSplit[0]).toDouble();
      i still read bufferSpilt[0].

      Can you please explain better?
      Of course you read bufferSpilt[0] - because that is what you wrote!
      So, what do you want to do?

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

      1 Reply Last reply
      0
      • B Offline
        B Offline
        banhmisua
        wrote on last edited by
        #3

        i read data from my COM and i save it in QStringList bufferSplit[0] and i plot it by using QCustomPlot.
        so i want convert bufferSplit[0] to double giatri and plot it. that's all.
        thank u.

        Christian EhrlicherC 1 Reply Last reply
        0
        • B banhmisua

          i read data from my COM and i save it in QStringList bufferSplit[0] and i plot it by using QCustomPlot.
          so i want convert bufferSplit[0] to double giatri and plot it. that's all.
          thank u.

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @banhmisua said in COM+QCustomPlot problem is QStringList[].toDouble():

          so i want convert bufferSplit[0] to double giatri and plot it. that's all.

          But you do it already...

          giatri=QString(bufferSplit[0]).toDouble()

          What's the content of bufferSplit[0] ? Please add

          qDebug() << "bufferSplit[0]:" << bufferSplit[0]

          and post it here.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • B Offline
            B Offline
            banhmisua
            wrote on last edited by
            #5

            @Christian-Ehrlicher . i did as u said. and i have problem.
            When i DEBUG step by step, everything is right!
            bufferSplit[0]: "82"
            bufferSplit[0]: "82"
            bufferSplit[0]: "82"
            bufferSplit[0]: "82"
            bufferSplit[0]: "240"
            bufferSplit[0]: "82"

            but when i RUN. i got:

            bufferSplit[0]: "82"
            bufferSplit[0]: "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u000082"
            bufferSplit[0]: "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u000082"
            bufferSplit[0]: "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u000082"
            So what is problem here? can u tell me how solve it?
            thank u very much.

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I don't see a problem here except that sometimes you get 0 as value which you have to handle. We don't know what 0 means in your context.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              0

              • Login

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