Results 1 to 2 of 2

Thread: Qcustomplot converter data in "setData"

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Dec 2024
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Qcustomplot converter data in "setData"

    Hello everyone,

    I made a program that collects data from an Arduino
    in x,y format in a listwidget. These x, y values ??must then be sent to the Qcustomplot and that's where there is a problem.

    There is a comma between x and y. They arrive like that from the Arduino to be used in the Excel graph.

    My problem is when collecting the data in the ui->customplot->graph(0)->setData(x,y) function;

    I can't convert the data from the "QString(data)" to convert them

    Here is the blocking part: (after ui->listwidget..)

    Qt Code:
    1. void NetworkPlot::readData()
    2. {
    3. qDebug() <<"Serialport works"; // it's ok (control port com)
    4. auto data = arduino->readAll(); // it's ok
    5. ui->listWidget->addItem(QString(data)); // it's ok
    6.  
    7. QString str = QString(data); // start of problem
    8. QStringList parts = str.split(" ");
    9. if (parts.size() == 2) {
    10. qDebug() << parts.at(1).toDouble() << parts.at(2).toDouble();
    11. mag.append(x) = parts.at(1).toDouble();
    12. num.append(y) = parts.at(2).toDouble();
    13.  
    14. QVector<double> mag;
    15. QVector<double> num;
    16. ui->customplot->graph(0)->setData(x,y);
    17. ui->customplot->replot();
    18. ui->customplot->update();
    19. }
    To copy to clipboard, switch view to plain text mode 
    My first test;

    Qt Code:
    1. void NetworkPlot::readData()
    2. {
    3. qDebug() <<"Serialport works"; //ok
    4. auto data = arduino->readAll(); //ok
    5. ui->listWidget->addItem(QString(data)); //ok
    6. QVector<double> x,y;
    7. ui->customplot->graph(0)->setData(x,y);
    8. ui->customplot->replot();
    9. ui->customplot->update();
    10. }
    To copy to clipboard, switch view to plain text mode 
    There is a formatting that totally escapes me and I spent hours testing. This is my first application in C++ and I only have knowledge in basic and arduino but it is progressing.

    I specify that I am French-speaking and I translate my request.

    Thank you for your help

    [IMG][/IMG]
    Last edited by d_stranz; 27th December 2024 at 22:03.

Similar Threads

  1. Replies: 1
    Last Post: 20th November 2015, 10:02
  2. Replies: 3
    Last Post: 16th March 2015, 07:31
  3. Replies: 1
    Last Post: 7th April 2010, 21:46
  4. Replies: 3
    Last Post: 25th August 2009, 13:03
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.