Seite 1 von 1

Qwt Plot

Verfasst: 22. Juli 2011 16:40
von js
Abend,
Versuche gerade einen realtime plot durchzuführen. Funktioniert schon ganz gut jedoch ist der erste Punkt mit dem letzten verbunden.
Wie bekomme ich das weg?
lg

Re: Qwt Plot

Verfasst: 22. Juli 2011 18:37
von ScyllaIllciz
Ich bin mir ziemlich sicher, dass in dem letzten Wert "0" drinnen steht ;-)

Re: Qwt Plot

Verfasst: 22. Juli 2011 19:02
von js
ne leider nicht habe es nochmal mit eigenen Werten getestet.
Er verbindet einen neuen Wert sofort mit dem aller ersten.

Code: Alles auswählen

// Die Variablen
int sx=0;
const int Size=27;
double xval[Size];
double yval[Size];

//Die plotfunktion
void tpopt::plot1()
{
xval[sx]=sx;
yval[sx]=thread1.ywertplot1; 

curve1->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush,
        QPen(Qt::black), QSize(5, 5) ) ); 
curve1->setPen(QColor(Qt::darkGreen));
curve1->setStyle(QwtPlotCurve::Lines);
curve1->setRawSamples(xval, yval, Size);
sx++; 
}
im Grunde ist nur der ywert wichtig der x Wert ist eine Laufvariable

Re: Qwt Plot

Verfasst: 22. Juli 2011 19:28
von ScyllaIllciz
mainwindow.h

Code: Alles auswählen

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <qwt_plot_curve.h>

const int MAX_VALUE = 10;
namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    double xValue[MAX_VALUE];
    double yValue[MAX_VALUE];
    QwtPlotCurve *curve;
};

#endif // MAINWINDOW_H
mainwindow.cpp

Code: Alles auswählen

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow),
    curve(new QwtPlotCurve)
{
    ui->setupUi(this);
    for (int i=0; i<MAX_VALUE; ++i){
        xValue[i]=i;
        yValue[i]=i;
    }

    curve->setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush,
            QPen(Qt::black), QSize(5, 5) ) );
    curve->setPen(QColor(Qt::darkGreen));
    curve->setStyle(QwtPlotCurve::Lines);

    curve->attach(ui->qwtPlot);
    curve->setRawSamples(xValue, yValue, MAX_VALUE);
    ui->qwtPlot->replot();

}

MainWindow::~MainWindow()
{
    delete ui;
}
main.cpp

Code: Alles auswählen

#include <QtGui/QApplication>
#include "mainwindow.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}
Funktioniert hier wie erwartet.

Re: Qwt Plot

Verfasst: 22. Juli 2011 19:35
von js
Edit: Vielen Dank für die Hilfe
Fehler gefunden.
Das Ding ist weiß nicht wie viele Werte noch kommen. Wenn Size größer ist als die Anzahl der Werte dann verbindet er es.
curve1->setRawSamples(xval, yval, sx);
sx++;
Läuft jetzt.