Hi,
yes i activated my QtSql module?
i checked my other application which i need to store data in the database..
i am sure that application is running good with all the values i enter is present in the database..
thanks in advance
Hi,
yes i activated my QtSql module?
i checked my other application which i need to store data in the database..
i am sure that application is running good with all the values i enter is present in the database..
thanks in advance
hi uwe is this how i have to retrive data from database and plot a graph from it. I am trying so much but not able to figure out a proper way to retrive data from database and plot . Pls tell where i am going wrong i have attached the project zip file.
Thank You
Hi all,
I have defined to get data from database to plot in this manner,
eventually i am facing an error,
stating like this
So what should i do now to correct this error..." void QwtPlotCurve::setData(const double *,const double *,int)' : cannot convert parameter 1 from 'double' to 'const double *' "
thanks in advance ..
This is the function for which i used to generate points from the database...
My Specification::
database table name:-- data_table;
table fields::- x[varchar], y[varchar]
Qt Code:
void test_plotdb::on_plotButton_clicked() { if (q.exec()) { q.first(); do { m_curve->setData(q.value(1).toDouble(),q.value(0).toDouble(), 100); m_curve->attach(myPlot); } while (q.next()); } else }To copy to clipboard, switch view to plain text mode
Hi friends pls help me out with this problem.?? I have one error, which i have posted above but some problem debugging it.
Thank You
The QwtPlotCurve::setData() variant you are trying to use expects two arrays of doubles, not plain doubles. You have to first collect all x-es and y-es in a two QLists and then pass them to setData().
hi jacek,
thanx for ur reply..
i tried to do in ur method.. but could not meet to actual requirements
i am getting the following errors using ur method...
can u solve.. them please.....
Qt Code:To copy to clipboard, switch view to plain text mode
These r the errors which i get doing so......
thanx in advance..: error C2065: 'Double' : undeclared identifier
.\test_plotdb.cpp(86) : error C2133: 'x_list' : unknown size
.\test_plotdb.cpp(86) : error C2512: 'QList' : no appropriate default constructor available
.\test_plotdb.cpp(87) : error C2662: 'QList<T>::append' : cannot convert 'this' pointer from 'QList' to 'QList<T> &'
Reason: cannot convert from 'QList' to 'QList<T>'
Conversion requires a second user-defined-conversion operator or constructor
.\test_plotdb.cpp(88) : error C2133: 'y_list' : unknown size
.\test_plotdb.cpp(88) : error C2512: 'QList' : no appropriate default constructor available
.\test_plotdb.cpp(89) : error C2662: 'QList<T>::append' : cannot convert 'this' pointer from 'QList' to 'QList<T> &'
Reason: cannot convert from 'QList' to 'QList<T>'
Conversion requires a second user-defined-conversion operator or constructor
.\test_plotdb.cpp(95) : error C2663: 'QList<T>::value' : 2 overloads have no legal conversion for 'this' pointer
.\test_plotdb.cpp(95) : error C2663: 'QList<T>::value' : 2 overloads have no legal conversion for 'this' pointer
C++ is case-sensitive --- it should be double not Double.
Also please explain with your own words what does this part of your code exactly do:Qt Code:To copy to clipboard, switch view to plain text mode
hi,
Qt Code:To copy to clipboard, switch view to plain text mode
Actually from the for loop i am explaining
taking a incremental value i and initializing that to the first value present in the query
this is the query which displays the values present in the database..QSqlQuery q("SELECT xval,yval FROM PlotGraph1");
taking a qlist and x_list which takes the x values present in the database...
assigning the values present in the database to x and y...
here x_list is being appended with the values of xval (first field) present in the database..
QList <double> x_list;
x_list.append(q.value(i));
similarlly
here y_list is being appended with the values of yval (second field) present in the database..
QList <double> y_list;
y_list.append(q.value(i));
Next
m_curve = new QwtPlotCurve();
m_curve->setPen(QPen(Qt::red));
m_curve->setData(x_list.value(i), y_list.value(i), 100);
m_curve->attach(myPlot);
myPlot->replot();
now i am initializing a curve as m_curve
taking red color to plot my curve, i initialized a pen over here..
m_curve->setData(x_list.value(i), y_list.value(i), 100);
this actually takes the values present in the x_list and y_list ..
nowm_curve->attach(myPlot);
myPlot->replot();
the above code will attach my curve to my qwtplot widget ie..(myPlot)
and plots the points based on the values taken above...
i kept this code in draw function and keep on calling @ 1sec rate with the timer....
I think i have explained every thing present in the code....
if i go wrong any where please correct me so that i will not repeat the mistake again...
thanks in advance...
giving or taking, both r the similar form's of getting knowledge...
Good, but there are few key words missing.
For each row in the query result you:
- create a new empty list called x_list,
- append a single value to x_list,
- create a new empty list called y_list,
- append a single value to y_list,
- create and setup a new curve,
- pass i-th elements of x_list and y_list and a magic value "100" to QwtPlotCurve::setData,
- attach the curve to the plot,
- replot the plot.
and you repeat that loop every second.
The questions are:
How many items are there in x_list and _ylist when the flow reaches point #6?
Where does this 100 come from?
Are there any steps that you could or should move out of that loop?
How many items are there in x_list and _ylist when the flow reaches point #6?
ANS::>>): --- depending up on the last value present in the database ie. currently my database consists of 13 values and i mean to say that x consists of 13 values along with y...
Q) Where does this 100 come from?
Actually 100 is the array size which is mentioned in the qwt_data class reference..
i am not sure about it... as a trail and error method i kept the value as 100 so that my plot would start from the 100th point assuming that there is some delay in order to plot the graph...
Are there any steps that you could or should move out of that loop?
i am not sure about ur third question? as i am a new to this world of qt,
the whole code which i had given u is being from an example... got from google..
which i modified that according to my requirement...
so sir, can u please tell me exactly what mistakes i have committed....
I have attached my program by the name " test_plotdb.cpp", "Connection.h"
please find them and have a glance at it....
Thanks for ur reply's
Always giving or taking is both ways of learning knowledge..
No, there's always exactly one item in x_list and y_list. Look at the 1--4 points --- in each iteration you create new empty lists. Please take some C++ tutorial and read about scopes and automatic variables.
The QwtPlotCurve::setData() docs say:The third parameter says how many items there are in xData and yData (in your case x_list and y_list respectively), so it can't be simply 100....
Parameters:
xData pointer to x values
yData pointer to y values
size size of xData and yData
...
The second problem is that three-parameter version of setData() is for double arrays and you now use QList< double >, so you have to use the two-parameter version.
The problem is not that you are new to Qt, but that you must learn to understand C++ code. You can't program anything if you don't understand what you write.
No, because you won't learn anything. First try to understand what exactly happens in that loop.
Bookmarks