qwtPlot->replot() results in segmentation fault
Hi all,
trying to plot in a Qt4 mainwindow, which was layouted with Qt designer. So I have a Ui_MainWindow class, which declares and defines QwtPlot *qwtPlot.
The Ui_MainWindow class is privately inherited by another class, lets call it PlotOri, in order to have access to all the graphical elements.
Here is the part of the constructor of PlotOri, where I try to use the replot() methode:
Code:
const double* t = times;
const double* r = recordings;
// add curves
// copy the data into the curves
curve1->setData(qwtArray);
// finally, refresh the plot
qwtPlot->replot();
At runtime I receive a 'Segmentation fault' and the program crashes. Commenting the last line prevents from crashing, but of course I also don't see a plot.
Maybe it is just a newbie's mistake. I hope you can help me and thx in advance.
greetz, kai
Re: qwtPlot->replot() results in segmentation fault
Is qwtPlot protected or private?
Re: qwtPlot->replot() results in segmentation fault
Hmmm, it's public... I can't guess what difference it makes.?
Ok, I also tried the public inheritance. Nothing changes.
Then I put the code from the first post into the 'Ui_MainWindow' class. It works. This of course not what I want to code. But I am puzzled, what that could mean.
Any help is highly appreciated.
greetz, kai
Re: qwtPlot->replot() results in segmentation fault
Tried it again on another machine. Same result. From that I conclude, it is not a problem with the memory.
Ok, let me ask another question: Is it possible to invoke a methode of an qwt object, in this case qwtplot, from within another class, in which the qwt object was not declared or defined? This other class will inherit the class in which the qwt object was declared and defined. So all methodes are available, right?
greetz, kai
Re: qwtPlot->replot() results in segmentation fault
Can you show a stack trace from your debugger? That will help finding the problem a great deal.
Re: qwtPlot->replot() results in segmentation fault
Quote:
Originally Posted by
kaizimir
Tried it again on another machine. Same result. From that I conclude, it is not a problem with the memory.
Ok, let me ask another question: Is it possible to invoke a methode of an qwt object, in this case qwtplot, from within another class, in which the qwt object was not declared or defined? This other class will inherit the class in which the qwt object was declared and defined. So all methodes are available, right?
greetz, kai
Well if qwtPlot was never instantiated (new'ed) before qwtPlot->replot() is called, then it will crash
Re: qwtPlot->replot() results in segmentation fault
Hey,
I am happy you are still there. First I am sorry if my terminology is not completly correct (I am new to all this): The object qwtPlot is 'newed' and I also see it in the mainwindow as central widget.
Second I am not sure what a stack trace is. I uploaded a screen shot of what I think is the stack trace on rapidshare:
http://rapidshare.com/files/27189930...Trace.png.html
Unfortunately KDBG and KDevelop have no copy&paste for this.
I substituted the data, which are loaded from a file and should be plotted, with very short arrays of just 10 values. I was suspicious, that my data might be the problem. But the problem remains. If I put the arrays in the class, where qwtPlot is instantiated, it is working fine.
Thanks for your patience,
kai
Re: qwtPlot->replot() results in segmentation fault
had the same problem because my scale had invalid ticks
Re: qwtPlot->replot() results in segmentation fault
Quote:
Originally Posted by
emrares
had the same problem because my scale had invalid ticks
I think it is not the same problem, because the problem as I described it is independent from the data.
Re: qwtPlot->replot() results in segmentation fault
hello man,
Try to do it:
ui.qwtPlot->replot(); <-- default vc++
or
ui->qwtPlot->replot(); <-- default mingw
hmmm, try to make QwtPlotCurve *curve1 global too ^^
QwtPlotCurve *curve1; in header and
curve1 = new QwtPlotCurve(); in .cpp
bye bye
Re: qwtPlot->replot() results in segmentation fault
Hey guys,
I am really desperate. Therefore I reconstructed my problem in a plain new project.
This is the constructor of the 'mainwindow' class, which is called by main:
Code:
#include <QObject>
#include <QMainWindow>
#include <QtGui>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_data.h>
#include "ui_GUI_mainwindow.h"
#include "m_mainwindow.h"
#include "m_plot.h"
M_MainWindow
::M_MainWindow(QWidget *parent
){
setupUi(this);
double x[] = {1, 2, 3, 4, 5};
const double* x_ptr = x;
const double* y_ptr = x;
curve1->setData ( qwtArray );
qwtPlot->replot();
// M_Plot qPlot; // <- HERE IS THE PROBLEM
}
The line is plotted in the qwt widget as expected. If I include:
'M_Plot qPlot;' the program crashes and I receive the 'segmentation fault' error. Compiling the program is not a problem.
This is the constructor for the M_Plot class:
Code:
#include <QObject>
#include <QMainWindow>
#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_data.h>
#include "ui_GUI_mainwindow.h"
#include "m_plot.h"
M_Plot::M_Plot()
{
double x[] = {2, 4, 6, 8, 10};
const double* x_ptr = x;
const double* y_ptr = x;
curve1->setData ( qwtArray );
qwtPlot->replot();
}
I really don't know what I am doing wrong. Maybe I am already blinded and can't find an obvious mistake.
I posted a stack trace in a previous post yesterday.
System specs:
openSUSE 11.1
qwt 5.2.0 -> from the repositories
Qt 4.4.3
gcc-c++ 4.3
KDevelop 3.5.3
greetz, kai
Edit: I just compiled qwt 5.2.0 from Sourceforge and used it in the program, but also didn't help. Damn it :mad:
Re: qwtPlot->replot() results in segmentation fault
Where is qwtPlot instantiated? Did u add it using the designer? If so, why isn't it ui.qwtPlot?
Re: qwtPlot->replot() results in segmentation fault
Here is the class generated by the designer, which instantiats qwtPlot:
Code:
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
{
if (MainWindow->objectName().isEmpty())
MainWindow
->setObjectName
(QString::fromUtf8("MainWindow"));
MainWindow->resize(800, 600);
centralwidget
= new QWidget(MainWindow
);
centralwidget
->setObjectName
(QString::fromUtf8("centralwidget"));
qwtPlot
->setObjectName
(QString::fromUtf8("qwtPlot"));
qwtPlot
->setGeometry
(QRect(40,
30,
721,
501));
MainWindow->setCentralWidget(centralwidget);
menubar
->setObjectName
(QString::fromUtf8("menubar"));
menubar
->setGeometry
(QRect(0,
0,
800,
24));
MainWindow->setMenuBar(menubar);
statusbar
->setObjectName
(QString::fromUtf8("statusbar"));
MainWindow->setStatusBar(statusbar);
retranslateUi(MainWindow);
} // setupUi
{
Q_UNUSED(MainWindow);
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
And this is the header of the M_MainWindow class I posted yesterday:
Code:
private Ui::MainWindow
{
Q_OBJECT
public:
M_MainWindow
( QWidget *parent
= 0 );
~M_MainWindow();
};
I think, the private Ui::MainWindow inheritance is the reason, why I don't need the ui.*...
I am really sorry to get on your nervs every day. But it is a real pity to have such a show stopper as a newby to C++, Qt and qwt when everything else works fine.
Re: qwtPlot->replot() results in segmentation fault
Hey,
I found the problem and I must admitt, that it is not related to qwt.
@jmsbc: You were right from the beginning, that it is a problem of instantiation and that the plot widget isn't accessible from where I wanted to use it.
I am doing it now by handing over a pointer to the qwt widget to the class that uses the plot. I am not very happy with that solution and hope to find a way with inheritance.
Thanks to all,
kai
Re: qwtPlot->replot() results in segmentation fault
I know I am a bit late to this thread, but you forgot to call setupUi(this) in the constructor of M_Plot.
Re: qwtPlot->replot() results in segmentation fault
this might be somewhat related, I found that replot() works well when I rescale my x-axis in Mac OS platform, but it does not respond/work when I use this in Linux? It's kind of strange. I wonder if this is related?
I just posted the details in a separate thread.