PDA

View Full Version : Graphs in Qt



qtlinuxnewbie
19th February 2010, 12:47
hi,

i need to draw graphs in my qt project.
as far as googling i came to know that to draw graphs in qt project , i need to use QWT.
so i downloaded from sourceforge.net and it got installed taking the qt3 (as my sytem is linux where qt 3 is default and i manually install qt4.1( creator) .

. so can any one guide me in using either qt4.1 or qt4.1+qwt to draw the graphs..


Thanks in advance...

Astronomy
19th February 2010, 17:12
Hi,
I'm using ubuntu and installed Qt4.5.3. and Qwt 5.2.0

Download Qwt 5.2. make all Files in the directory: chown -R a+rwx
compile it with qt for the qwt examples..
use:

http://qwt.sourceforge.net/class_qwt_plot.html

#include <qwt_plot.h>
#include <qwt_plot_curve.h>

QwtPlot *myPlot = new QwtPlot("Two Curves", parent);

// add curves
QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");

// copy the data into the curves
curve1->setData(...);
curve2->setData(...);

curve1->attach(myPlot);
curve2->attach(myPlot);

// finally, refresh the plot
myPlot->replot();


Or if you subclass your own
class CMyPlot : public QwtPlot
{
...
}

and draw the curves in the constructor...
CMyPlot ::CMyPlot()
{
...
QwtPlotCurve cCurve = new QwtPlotCurve( PlotFileName1 );

#if QT_VERSION >= 0x040000
cCurve->setRenderHint(QwtPlotItem::RenderAntialiased);
#endif
cCurve->setPen(QPen(Qt::blue));
cCurve->attach(this);
cCurve->setData(Wavelength, Flux); // here your arrays must fit in
...
}

greetz Astronomy

qtlinuxnewbie
20th February 2010, 04:08
Thnk u very much for ur suggestion and sample program.
but

Download Qwt 5.2. make all Files in the directory
i dint get u for the above lines.

i hve installed my qt4.1 in the /opt directory.
so can u help me in details where to (directories) install the qwt including the steps and also
place the libraries.

i have a doubt::confused::confused:
can i use the qwt_plot.h directly in qt project??? after getting sucessfuly installed..

Thnk u in advance...

Astronomy
20th February 2010, 09:09
Hi,
read the file INSTALL and/or Trolltechs qmake documentation. Once you have build the library you have to install all files from the lib, include and doc directories.
http://qwt.sourceforge.net/qwtinstall.html

Ah.. i've ment: make the directory + files: read/write/executable ( := rwx) ;)
Hmm.. why don't you install Qt4.5 or Qt4.6? Follow the instructions and everything is fine.

in short:
No, do not include the file manually. First compile Qwt with Qt. this will make all libraries you need.
You must set at the bottom of your Project file: *.pro these lines:

INCLUDEPATH += /home/orwherever/qwt-5.2/lib
LIBS += -lqwt

My Project settings look like: (in Qt/Project/Build Settings/Debug - Build Environment)
LD_LIBRARY_PATH /opt/qtsdk-2009.04/lib/qtcreator:/home/orwherever/qwt-5.2/lib
PATH /opt/qtsdk-2009.04/qt/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/home/qwt-5.2/bin:/home/user/qwt-5.2/src
PWD /home/user:/home/user/qwt-5.2/src
QWTLIB /lib:/home/user/qwt-5.2/lib/:/home/workingdirectoryofapplication/bin/lib

but some lines may be redundant..
if your compiler didn't get through with -lqwt, install these libs. under ubuntu they are called libqwt and not lqwt!!! (i was looking a little time before i found out :o)

greetz A.

qtlinuxnewbie
20th February 2010, 12:01
thank you very much ..
i will follw the steps and get back to u if necessasary..