Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
void PlottingGraph::draw()
{
m_time++;
memmove(m_y, &m_y[1], 99 * sizeof(double));
m_y[99] = 10 * sin((double)m_time / 360 * 3.1415 * 10) + rand() % 4000 -2000;
for (int i = 0; i < 100; i++)
m_x[i]++;
if (!m_curve)
{
m_curve = new QwtPlotCurve();
m_curve->setPen(QPen(Qt::red));
m_curve->setData(m_x, m_y, 100);
m_curve->attach(myPlot);
}
m_curve->setData(m_x, m_y,100);
myPlot->setAxisScale(QwtPlot::xBottom, m_time, m_time +100);
}
|
|
|
Source code |
1 |
m_y[99] = 10 * sin((double)m_time / 360 * 3.1415 * 10) + rand() % 4000 -2000; |
|
|
Source code |
1 2 3 4 5 6 |
QSqlDatabase db = QSqlDatabase::addDatabase( "QMYSQL", "test" ); db.setHostName( "..." ); db.setDatabaseName( "..." ); db.setUserName( "..." ); db.setPassword( "..." ); db.open(); |
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 |
QSqlQuery q( QSqlDatabase::database( "test" ) );
if( q.exec( "select x, y from data_table order by x;" ) )
{
nb = q.size();
x = new double[nb];
y = new double[nb];
for( int i = 0; q.next(); i++ )
{
x[i] = q.value(0).toDouble();
y[i] = q.value(0).toDouble();
}
}
|

This post has been edited 1 times, last edit by "crazycoder" (May 16th 2008, 5:31pm)
This post has been edited 1 times, last edit by "crazycoder" (May 17th 2008, 5:45am)
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#include <QSqlQuery>
#include <QMenu>
plot_db::plot_db(QWidget *parent)
: QMainWindow(parent)
, m_curve(0)
{
ui.setupUi(this);
QTimer *timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(draw()));
timer->start(1000);
myPlot->setTitle("Pressure ");
myPlot->setAxisTitle(QwtPlot::xBottom, " System time [h:m:s]");
myPlot->setAxisScale(QwtPlot::xBottom, 0,60 );
myPlot->setAxisTitle(QwtPlot::yLeft, "Degree");
myPlot->setAxisScale(QwtPlot::yLeft, -60,60 );
myPlot->setAutoReplot(true);
}
plot_db::~plot_db()
{
}
void plot_db::draw()
{
QSqlQuery q;
if( q.exec( "select s_x, s_y from data_table order by x;" ) )
{
nb = q.size();
s_x = new double[nb];
s_y = new double[nb];
for( int i = 0; q.size(); i++ )
{
s_x[i] = q.value(0).toDouble();
s_y[i] = q.value(0).toDouble();
}
}
m_curve = new QwtPlotCurve();
m_curve->setPen(QPen(Qt::red));
m_curve->setData(s_x, s_y, 100);
m_curve->attach(myPlot);
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#include "qwt_plot.h"
#include <qwt_plot_curve.h>
using namespace Ui;
class plot_db : public QMainWindow, public plot_dbClass
{
Q_OBJECT
public:
plot_db(QWidget *parent = 0);
~plot_db();
private slots:
void draw();
private:
int nb;
QwtPlotCurve *m_curve;
double s_x[100];
double s_y[100];
Ui::plot_dbClass ui;
};
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#ifndef CONNECTION_H
#define CONNECTION_H
#include <QtGui/QMainWindow>
#include <QtSql>
#include <QMessageBox>
#include <QTableView>
inline bool createConnection()
{
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(" Plot_DB ");
if (!db.open())
{
QMessageBox::critical(0, qApp->tr("Cannot open database"),
qApp->tr("Unable to establish a database connection.\n"
"This example needs SQLite support. Please read "
"the Qt SQL driver documentation for information how "
"to build it.\n\n"
"Click Cancel to exit."), QMessageBox::Cancel);
return false;
}
QSqlQuery query;
if (!query.exec("create table if not exists data_table(s_x varchar(20) primary key, "
"s_y varchar(20))"))
{
QMessageBox::critical(0, "Failed", "Failed create Te table");
return false;
}
query.exec("insert into data_table values(0,-60 )");
query.exec("insert into Acquisition values(10, 0)");
query.exec("insert into Acquisition values(20, 40)");
query.exec("insert into Acquisition values(28, 0)");
query.exec("insert into Acquisition values(30, -30)");
query.exec("insert into Acquisition values(38, 0)");
query.exec("insert into Acquisition values(40, 38 )");
query.exec("insert into Acquisition values(50, 0 )");
query.exec("insert into Acquisition values(52,-30 )");
query.exec("insert into Acquisition values(55, 0)");
query.exec("insert into Acquisition values(60,50)");
return true;
}
#endif
|
|
|
Source code |
1 2 3 4 5 |
.\plot_db.cpp(44) : error C2440: '=' : cannot convert from 'double *' to 'double [100]' There are no conversions to array types, although there are conversions to references or pointers to arrays .\plot_db.cpp(45) : error C2440: '=' : cannot convert from 'double *' to 'double [100]' There are no conversions to array types, although there are conversions to references or pointers to arrays main.cpp |
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
/* *****************test_plotdb.cpp****************** */
m_sqlModel = new QSqlQueryModel(this);
QSqlQuery q("SELECT xval,yval FROM data_table1");
if (q.exec())
{
for(int i=q.first();i<q.last();i++)
{
*s_x=q.value(0).toDouble();
*s_y=q.value(1).toDouble();
m_curve = new QwtPlotCurve();
m_curve->setPen(QPen(Qt::red));
m_curve->setData((const double*)s_x, (const double*)s_y, 100);
//m_curve->setRawData(s_x,s_y,Size);
m_curve->attach(myPlot);
myPlot->replot();
}
}
else
{
QMessageBox::critical(this, "Failure", "Query failure");
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/* *****************test_plotdb.h****************** */
class test_plotdb : public QDialog,public Ui::test_plotdbClass
{
Q_OBJECT
public:
test_plotdb(QWidget *parent = 0);
~test_plotdb();
private slots:
void draw();
// Ui::test_plotdbClass ui;
private:
QwtPlotCurve *m_curve;
QSqlQueryModel *m_sqlModel;
int nb;
double *s_x;
double *s_y;
private slots:
void on_plotButton_clicked();
};
|