PDA

View Full Version : Qwt examples



31512
30th June 2008, 14:42
Hi to all! Some time ago I downloaded Qwt. All OK. Compiling OK. Installing OK.
A troubles with using in project was resolved successfully. But I need a histogram.
Well, there is an example present in source code. Good. Building... OK.
Trying to start examples one by one.
bode - segmentation fault :confused:
cpuplot - symbol lookup error: ./cpuplot: undefined symbol: _ZNK9QwtLegend4findEPK20QwtLegendItemManager ????
curvedemo1, curvedemo1 - segmentation fault :confused: :mad:
data_plot - segmentation fault :-/
dials - ok :-D
event_filter - ok :-)
histogram - segmentation fault :-/
radio - ok :-D
realtime - segmentation fault :-/
simple - segmentation fault :-/
sliders - ok :-D
spectrogram - segmentation fault >:-/
sysinfo - ok :-)

So, it`s a pity, but I can`t see most interesting examples. Well. I`m trying to write a histogram for my project. Step by step I`m trying to understand what`s wrong with example "histogram". As I understood there are no class like QwtHistogram. So, in example I have


class HistogramItem: public QwtPlotItem
{
public:
explicit HistogramItem(const QString &title = QString::null);
explicit HistogramItem(const QwtText &title);
virtual ~HistogramItem();

void setData(const QwtIntervalData &data);
const QwtIntervalData &data() const;

void setColor(const QColor &);
QColor color() const;

virtual QwtDoubleRect boundingRect() const;

virtual int rtti() const;

virtual void draw(QPainter *, const QwtScaleMap &xMap,
const QwtScaleMap &yMap, const QRect &) const;

void setBaseline(double reference);
double baseline() const;

enum HistogramAttribute
{
Auto = 0,
Xfy = 1
};

void setHistogramAttribute(HistogramAttribute, bool on = true);
bool testHistogramAttribute(HistogramAttribute) const;

protected:
virtual void drawBar(QPainter *,
Qt::Orientation o, const QRect &) const;

private:
void init();

class PrivateData;
PrivateData *d_data;
};


I wrote a test as copy of example:


#include <stdlib.h>
#include <qapplication.h>
#include <qpen.h>
#include <qwt_plot.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_marker.h>
#include <qwt_interval_data.h>
#include "histogram_item.h"

int main(int argc, char **argv)
{
QApplication a(argc, argv);

QwtPlot* plot = new QwtPlot(0);
plot->setCanvasBackground(QColor(Qt::white));
plot->setTitle("Histogram");

QwtPlotGrid *grid = new QwtPlotGrid;
grid->enableXMin(true);
grid->enableYMin(true);
grid->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
grid->setMinPen(QPen(Qt::gray, 0 , Qt::DotLine));
grid->attach(plot);

HistogramItem *histogram = new HistogramItem();
histogram->setColor(Qt::darkCyan);

const int numValues = 20;

QwtArray<QwtDoubleInterval> intervals(numValues);
QwtArray<double> values(numValues);

double pos = 0.0;
for ( int i = 0; i < (int)intervals.size(); i++ )
{
const int width = 5 + rand() % 15;
const int value = rand() % 100;

intervals[i] = QwtDoubleInterval(pos, pos + double(width));
values[i] = value;

pos += width;
}

histogram->setData(QwtIntervalData(intervals, values));
histogram->attach(plot);

plot->setAxisScale(QwtPlot::yLeft, 0.0, 100.0);
plot->setAxisScale(QwtPlot::xBottom, 0.0, pos);
plot->replot();

#if QT_VERSION < 0x040000
a.setMainWidget(&plot);
#endif

plot->resize(600,400);
plot->show();

return a.exec();
}

and got segmentation fault in return a.exec();

Can you help me? Were is problem may be? May be another way present to make histogram?
Thanks a lot everyone!

DKL1972
30th June 2008, 23:05
I can't help with your seg faults but if you are interested in a histogram, I am using the QwtPlotHistogram which is in the SVN development trunk (5.2). I have found it quite useful.

-Dean

31512
1st July 2008, 04:29
I can't help with your seg faults but if you are interested in a histogram, I am using the QwtPlotHistogram which is in the SVN development trunk (5.2). I have found it quite useful.
-Dean
Thanks a lot! All OK, but at


QwtPlotHistogram *histogram = new QwtPlotHistogram();

I`ve got:
/home/Andrei/Projects/Rados/RadosSeparatorQT/RadosSeparatorQT: symbol lookup error: /home/Andrei/Projects/Rados/RadosSeparatorQT/RadosSeparatorQT: undefined symbol: _ZN16QwtPlotHistogramC1ERK7QString
Trying to to understand this...

31512
1st July 2008, 05:15
I is seems that I`ve got dynamically linking problem...
my *.pro file:


QWT_ROOT = qwt

include( $${QWT_ROOT}/qwtconfig.pri )

SUFFIX_STR =
VVERSION = $$[QT_VERSION]
isEmpty(VVERSION) {

# Qt 3
debug {
SUFFIX_STR = $${DEBUG_SUFFIX}
}
else {
SUFFIX_STR = $${RELEASE_SUFFIX}
}
}
else {
CONFIG(debug, debug|release) {
SUFFIX_STR = $${DEBUG_SUFFIX}
}
else {
SUFFIX_STR = $${RELEASE_SUFFIX}
}
}

INCLUDEPATH += $${QWT_ROOT}/src
DEPENDPATH += $${QWT_ROOT}/src
QWTLIB = qwt$${SUFFIX_STR}
LIBS += -L$${QWT_ROOT}/lib -l$${QWTLIB}

TEMPLATE = app
TARGET = RadosSeparatorQT
QT += core \
gui \
xml \
network \
thread
HEADERS += header1.h \
header2.h \
...

SOURCES += source1.cpp \
source2.cpp \
...
FORMS += Form1.ui \
Form2.ui \
...
RESOURCES += Resource.qrc


is it correct?

31512
1st July 2008, 11:32
Another variant of *.pro file


INCLUDEPATH += qwt/src
unix:LIBS += -L/qwt/lib -llibqwt
TEMPLATE = app
TARGET = RadosSeparatorQT
QT += core \
gui \
xml \
network \
thread
HEADERS += header1.h \
header2.h \
...
SOURCES += source1.cpp \
source2.cpp \
...
FORMS += Form1.ui \
Form2.ui \
...
RESOURCES += Resource.qrc


So. I`ve got from from SVN development trunk version 5.2. Before compile and install I changed in qwt.pri CONFIG += QwtDll to CONFIG -= QwtDll. And as result I have libqwt.a (instead of libqwt-5.2.so). Static library. While compiling and installing no any problems. I`ve copied lib and src subdirectory into qwt subdirectory of my project. While compiling project no any trouble. A trouble at linking!



cd '/home/Andrei/Projects/Rados/RadosSeparatorQT' && LC_MESSAGES="C" LC_CTYPE="C" gmake -k
linking RadosSeparatorQT (g++)
/usr/bin/ld: cannot find -llibqwt
collect2: ld returned 1 exit status
gmake: *** [RadosSeparatorQT] Error 1
gmake: Target `first' not remade because of errors.
*** Exited with status: 2 ***


Why it can`t find library? A path to it is correct.

jacek
2nd July 2008, 02:12
unix:LIBS += -L/qwt/lib -llibqwt
It should be:

unix:LIBS += -L/qwt/lib -lqwt

31512
2nd July 2008, 09:36
It should be:

unix:LIBS += -L/qwt/lib -lqwt

My respect to you! It works! It must be admitted that, the truth is that I am old stupid monkey! Can you explain why it should be -L/qwt/lib -lqwt, but not -L/qwt/lib -llibqwt?

31512
2nd July 2008, 10:09
All was good until I wrote


WidgetFrameCommonView::WidgetFrameCommonView( QWidget *parent )
: QWidget( parent )
{
setupUi( this );

QwtPlotHistogram *histogram = new QwtPlotHistogram();
//histogram->setStyle(QwtPlotHistogram::Columns);
//histogram->setPen(QPen(Qt::black));
//histogram->setBrush(QBrush(Qt::gray));
//histogram->attach(Plot);
//Plot->replot();

CommonInfoPanel->SetBackGroundColor( Qt::lightGray );
SeparatorsPanelsPanel->SetBackGroundColor( Qt::gray );
gridLayout->setContentsMargins( 0, 0, 0, 0 );
gridLayout->setSpacing( 0 );
}


linking RadosSeparatorQT (g++)
WidgetFrameCommonView.o: In function `WidgetFrameCommonView':
/home/Andrei/Projects/Rados/RadosSeparatorQT/Frames/WidgetFrameCommonView.cpp:9: undefined reference to `QwtPlotHistogram::QwtPlotHistogram(QString const&)'
/home/Andrei/Projects/Rados/RadosSeparatorQT/Frames/WidgetFrameCommonView.cpp:9: undefined reference to `QwtPlotHistogram::QwtPlotHistogram(QString const&)'
collect2: ld returned 1 exit status
gmake: *** [RadosSeparatorQT] Error 1
gmake: Target `first' not remade because of errors.
*** Exited with status: 2 ***

Without
QwtPlotHistogram *histogram = new QwtPlotHistogram(); linking is successful. As I understood class QwtPlotHistogram have some bugs?



class QWT_EXPORT QwtPlotHistogram: public QwtPlotSeriesItem<QwtIntervalSample>
{
public:
enum CurveStyle
{
NoCurve,

Outline,

Columns,
Lines,

UserCurve = 100
};

explicit QwtPlotHistogram(const QString &title = QString::null);
explicit QwtPlotHistogram(const QwtText &title);
virtual ~QwtPlotHistogram();

...
};
#endif

31512
2nd July 2008, 10:50
Histogram example was compiled and linked successfully. Executed successfully too. I`m perplexed... My program still generating link errors.

31512
2nd July 2008, 13:02
OK. Problem solved successfully. Including examples.pri (with some modifications) to *.pro file of my project makes wonder...

jacek
2nd July 2008, 22:00
Can you explain why it should be -L/qwt/lib -lqwt, but not -L/qwt/lib -llibqwt?
It's UNIX naming convention. All library file names start with "lib", so somebody in the Olde Days decided to skip it in linker options.

31512
3rd July 2008, 05:00
It's UNIX naming convention. All library file names start with "lib", so somebody in the Olde Days decided to skip it in linker options.
Thanks a lot! Live and learn... RTFM for me. :)