Skip to content
  • 0 Votes
    3 Posts
    220 Views
    timob256T

    @wrosecrans

    #include "qcustomplot.h" // Инициализируем объект полотна для графика wGraphic = new QCustomPlot(); ui->gridLayout->addWidget(wGraphic,2,0,5,5); // и устанавливаем // Добавляем график на полотно wGraphic->addGraph(wGraphic->xAxis, wGraphic->yAxis); // Подписываем оси координат wGraphic->xAxis->setLabel("итерации"); wGraphic->yAxis->setLabel("Дб"); // Устанавливаем максимальные и минимальные значения координат wGraphic->xAxis->setRange(0,100); wGraphic->yAxis->setRange(-50,50); // Отрисовываем содержимое полотна wGraphic->replot(); // добавляем красную линию на график wGraphic->addGraph(); // red line wGraphic->graph(0)->setPen(QPen(QColor(255, 110, 40))); // чистим старое отрисовываем новое wGraphic->graph(0)->clear(); wGraphic->graph(0)->rescaleAxes(); wGraphic->graph(0)->setData(y,x); // Устанавливаем координаты точек графика wGraphic->replot(); // Отрисовываем содержимое полотна
  • 0 Votes
    2 Posts
    342 Views
    timob256T

    @timob256 In general , there was one mistake , for some reason I thought that by setting the size of the vector , it would correct everything itself , but it turned out not to be so

    void MainWindow::slotProcessDatagrams() { QByteArray baDatagram_in; do { baDatagram_in.resize(m_pudp_in->pendingDatagramSize()); m_pudp_in->readDatagram(baDatagram_in.data(), baDatagram_in.size()); } while(m_pudp_in->hasPendingDatagrams()); QDataStream in(&baDatagram_in, QIODevice::ReadOnly); in.setVersion(QDataStream::Qt_5_3); in >> str_priem; // принимаем сообщение str_x = str_priem.section(' ',0,0); str_y = str_priem.section(' ',1); if(my_int >= 80) { // clear firs element // x.pop_back(); // y.pop_back(); // x.removeLast(); // y.removeLast(); x.pop_front(); //последний из вектора y.pop_front(); x << str_x.toDouble(); y << str_y.toDouble(); } else { x << str_x.toDouble(); y << str_y.toDouble(); my_int = my_int + 1; } // чистим старое отрисовываем новое wGraphic->graph(0)->clear(); wGraphic->graph(0)->rescaleAxes(); // wGraphic->replot(); // Отрисовываем содержимое полотна wGraphic->graph(0)->setData(y,x); // Устанавливаем координаты точек графика wGraphic->replot(); // Отрисовываем содержимое полотна // Очищаем принятую строку str_priem.clear(); }

    True, a new error jumped (for some reason the last and first point somehow connects, I don't know how to break)

    введите сюда описание изображения

  • 0 Votes
    2 Posts
    866 Views
    jsulmJ

    @JPolo said in Unable to compile when using QCustomPlot:

    I use Qt Creator 4.15.0 based on Qt 5.15.2 MSVC2019

    That is not necesserilly Qt version you're using (this is the Qt version used to build QtCreator).
    What Qt version did you install?

    What is the first error message?
    Did you do what the tutorial suggests: "To use the shared library in your application, set the define QCUSTOMPLOT_USE_LIBRARY before including the QCustomPlot header."?

  • 0 Votes
    5 Posts
    286 Views
    S

    @SGaist oh!i know,thanks!

  • 0 Votes
    6 Posts
    2k Views
    S

    Okay, I could fix the issue. The problem was my statement for resetting the plot.
    I used the following:

    for( int g=0; g<3; g++ ) { ui->plot_acceleration->graph(g)->data().clear(); } ui->plot_acceleration->replot();

    Then I tried the following like it is mentioned here:

    pq_plot->graph(g)->data().data().clear();

    But then the error occurs:

    error: member reference type 'QCPDataContainer<QCPGraphData> *' is a pointer; did you mean to use '->'?

    Then I used the autocorrection of Qt creator ('->' instead of ' . ')

    for( int g=0; g<3; g++ ) { ui->plot_acceleration->graph(g)->data().data()->clear(); } ui->plot_acceleration->replot();

    And it is working now. Still don't know what exactly happens with the plot, when I use the first statement... When I use the first statement the plots are also gone after clicking on reset...

  • 0 Votes
    4 Posts
    2k Views
    T

    Thank you both, it works now.

  • 0 Votes
    3 Posts
    906 Views
    S

    @vmanso said in Using QCustomPlot with Qt Quick (QML) instead of QWidget?:

    @SpaceToon Why not just use QtCharts instead of QCustomPlot ?
    https://doc.qt.io/qt-5/qtcharts-index.html

    But is it possible du plot sensor data via Bluetooth Low Energy in real time like this:

    Click for the video

  • 0 Votes
    4 Posts
    2k Views
    S

    @aha_1980 Thank you alot Sir your answer was correct and helped to clean up the problem!

    Regards

  • QCustomPlot QML

    Unsolved General and Desktop
    6
    0 Votes
    6 Posts
    4k Views
    DoohamD

    @jsulm ok I found out the solution. I had to change the engine for a QQuickView in the main.cpp. But is there any method to create a new kind if widget un qml and insert It like I can maje with a button ?

  • 0 Votes
    2 Posts
    856 Views
    ?

    Hi! QCustomPlot is 3rd party software. They have their own forum over here.

  • 0 Votes
    2 Posts
    3k Views
    Paul ColbyP

    Just a small note for anyone else interested: there's some further discussion on this over on the QCustomPlot forums too.

    Cheers.

  • 0 Votes
    14 Posts
    6k Views
    SGaistS

    Again: currently it's not yet part of Qt's OpenSource offering so you have to clone it using git and built it by hand. The repository is here

  • 0 Votes
    2 Posts
    3k Views
    SGaistS

    Hi and welcome to devnet,

    Don't get me wrong but are you aware that you are comparing a Dual Core 2GHz (so 2 Core at 2GHz) with 4GB of RAM and a low power ARM processor at 700MHz with 512MB or RAM ? Not to mention the GPU power levels that are also pretty different.

    The first thing I'd check is how much data you are trying to process and show and optimize that.

  • 0 Votes
    2 Posts
    3k Views
    SGaistS

    Hi,

    From a quick look at the setting up page, are you including the sources of QCustomPlot in your project ?

  • 0 Votes
    8 Posts
    4k Views
    T

    @TheHawk

    Have you tried giving argument to addGraph()? I don't remember whether the default argument translate well to javascript. If that still doesn't work, you can try to make add a dummy QObject class with Q_INVOKABLE functions to your engine to see if the problem is in your code or some possible interaction with QCustomPlot

  • 0 Votes
    1 Posts
    1k Views
    No one has replied
  • 0 Votes
    2 Posts
    2k Views
    B

    @borasemiz
    I have solved it. I discovered that I needed to refresh my plot, which is to say I needed to re-plot my plot. Let me:

    //I am just skipping to the click function of my button QCPItemStraightLine* line = (QCPItemStraightLine) (ui->widget->item()); line->point1->setCoords(5,6); line->point2->setCoords(5,7); ui->widget->replot(); //This line solved the problem.
  • 0 Votes
    2 Posts
    1k Views
    P

    Yeah I solved it.
    It had something to do with the break layout button in the designer mode.

  • 0 Votes
    6 Posts
    6k Views
    FranckynosF

    @vishnu said:

    May i know the use of it?

    yes it's a bool at false in constructor you have forget event in prototype :
    'virtual bool QWidget::event(QEvent*)' without object in => 'virtual bool QWidget::event(QEvent* !!! event !!! )' without object CustomPlot::CustomPlot(QWidget *parent) :QCustomPlot(parent) { setAttribute(Qt::WA_AcceptTouchEvents); _release2touch = false; _touchDevice = false; } bool CustomPlot::event(QEvent* event) { if(_touchDevice) { if(event->type() == QEvent::MouseButtonDblClick || event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease || event->type() == QEvent::MouseMove || event->type() == QEvent::MouseTrackingChange) { event->ignore(); return true; } if(event->type() == QEvent::Wheel) _touchDevice = false; } if(event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd ){ if(!_touchDevice) _touchDevice = true; QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints(); if(touchPoints.count() == 1 && touchEvent->touchPointStates().testFlag(Qt::TouchPointReleased)) _release2touch = false; if (touchPoints.count() == 1 && !_release2touch) { switch (event->type()) { case QEvent::TouchBegin: { QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); QTouchEvent::TouchPoint touchPoints = touchEvent->touchPoints().first(); QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonPress, touchPoints.pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); mousePressEvent(e); //==> meilleure methode }break; case QEvent::TouchUpdate: { QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); QTouchEvent::TouchPoint touchPoints = touchEvent->touchPoints().first(); QMouseEvent *e = new QMouseEvent(QEvent::MouseMove, touchPoints.pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); mouseMoveEvent(e); }break; case QEvent::TouchEnd:{ QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event); QTouchEvent::TouchPoint touchPoints = touchEvent->touchPoints().first(); QMouseEvent *e = new QMouseEvent(QEvent::MouseButtonRelease, touchPoints.pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); mouseReleaseEvent(e); }break; default: break; } }else if (touchPoints.count() == 2) { _release2touch = true; // determine scale factor const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first(); const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();// touchPoints.last(); double currentScaleFactor = QLineF(touchPoint0.pos(), touchPoint1.pos()).length() / QLineF(touchPoint0.lastPos(), touchPoint1.lastPos()).length(); QPointF centreZoom = QPointF((touchPoint0.pos().x()+ touchPoint1.pos().x())/2 , (touchPoint0.pos().y()+ touchPoint1.pos().y())/2); QPointF lastCenterZoom = QPointF((touchPoint0.lastPos().x()+ touchPoint1.lastPos().x())/2 , (touchPoint0.lastPos().y()+ touchPoint1.lastPos().y())/2); if (touchEvent->touchPointStates().testFlag(Qt::TouchPointReleased)) currentScaleFactor = 1; if(currentScaleFactor<1) currentScaleFactor = currentScaleFactor + (1-currentScaleFactor)/8; else currentScaleFactor = currentScaleFactor+ (currentScaleFactor-1)/8; currentScaleFactor =1/currentScaleFactor; double diffX = this->xAxis->pixelToCoord(lastCenterZoom.x()) - this->xAxis->pixelToCoord(centreZoom.x()); double diffY = this->yAxis->pixelToCoord(lastCenterZoom.y()) - this->yAxis->pixelToCoord(centreZoom.y()); if(!touchEvent->touchPointStates().testFlag(Qt::TouchPointReleased)){ this->xAxis->moveRange(diffX); this->yAxis->moveRange(diffY); this->xAxis->scaleRange(currentScaleFactor,this->xAxis->pixelToCoord(centreZoom.x())); this->yAxis->scaleRange(currentScaleFactor,this->yAxis->pixelToCoord(centreZoom.y())); this->replot(); } } return true; } return QWidget::event(event); }