Results 1 to 16 of 16

Thread: qwtPlot->replot() results in segmentation fault

  1. #1
    Join Date
    Jul 2009
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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:

    Qt Code:
    1. const double* t = times;
    2. const double* r = recordings;
    3.  
    4. QwtArrayData qwtArray(t, r, 10);
    5.  
    6. // add curves
    7. QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
    8.  
    9. // copy the data into the curves
    10. curve1->setData(qwtArray);
    11.  
    12. curve1->attach(qwtPlot);
    13.  
    14. // finally, refresh the plot
    15. qwtPlot->replot();
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Re: qwtPlot->replot() results in segmentation fault

    Is qwtPlot protected or private?

  3. #3
    Join Date
    Jul 2009
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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
    Last edited by kaizimir; 24th August 2009 at 21:28.

  4. #4
    Join Date
    Jul 2009
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  5. #5
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  6. #6
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default Re: qwtPlot->replot() results in segmentation fault

    Quote Originally Posted by kaizimir View Post
    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

  7. #7
    Join Date
    Jul 2009
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  8. #8
    Join Date
    Aug 2009
    Posts
    33
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: qwtPlot->replot() results in segmentation fault

    had the same problem because my scale had invalid ticks

  9. #9
    Join Date
    Jul 2009
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qwtPlot->replot() results in segmentation fault

    Quote Originally Posted by emrares View Post
    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.

  10. #10
    Join Date
    Jul 2009
    Location
    São Paulo - Brasil
    Posts
    20
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

  11. #11
    Join Date
    Jul 2009
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question 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:

    Qt Code:
    1. #include <QObject>
    2. #include <QMainWindow>
    3. #include <QtGui>
    4.  
    5. #include <qwt_plot.h>
    6. #include <qwt_plot_curve.h>
    7. #include <qwt_data.h>
    8.  
    9. #include "ui_GUI_mainwindow.h"
    10. #include "m_mainwindow.h"
    11. #include "m_plot.h"
    12.  
    13. M_MainWindow::M_MainWindow(QWidget *parent)
    14. : QMainWindow(parent)
    15. {
    16. setupUi(this);
    17.  
    18. double x[] = {1, 2, 3, 4, 5};
    19. const double* x_ptr = x;
    20. const double* y_ptr = x;
    21.  
    22. QwtArrayData qwtArray ( x_ptr, y_ptr, 5 );
    23.  
    24. QwtPlotCurve *curve1 = new QwtPlotCurve ( "Curve 1" );
    25.  
    26. curve1->setData ( qwtArray );
    27.  
    28. curve1->attach( qwtPlot );
    29.  
    30. qwtPlot->replot();
    31.  
    32. // M_Plot qPlot; // <- HERE IS THE PROBLEM
    33.  
    34. }
    To copy to clipboard, switch view to plain text mode 

    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:
    Qt Code:
    1. #include <QObject>
    2. #include <QMainWindow>
    3.  
    4. #include <qwt_plot.h>
    5. #include <qwt_plot_curve.h>
    6. #include <qwt_data.h>
    7.  
    8. #include "ui_GUI_mainwindow.h"
    9. #include "m_plot.h"
    10.  
    11. M_Plot::M_Plot()
    12. {
    13. double x[] = {2, 4, 6, 8, 10};
    14. const double* x_ptr = x;
    15. const double* y_ptr = x;
    16.  
    17. QwtArrayData qwtArray ( x_ptr, y_ptr, 5 );
    18.  
    19. QwtPlotCurve *curve1 = new QwtPlotCurve ( "Curve 1" );
    20.  
    21. curve1->setData ( qwtArray );
    22.  
    23. curve1->attach( qwtPlot );
    24.  
    25. qwtPlot->replot();
    26. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by kaizimir; 28th August 2009 at 21:57.

  12. #12
    Join Date
    Apr 2008
    Posts
    53
    Thanks
    10

    Default 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?
    Last edited by jmsbc; 29th August 2009 at 02:04.

  13. #13
    Join Date
    Jul 2009
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: qwtPlot->replot() results in segmentation fault

    Here is the class generated by the designer, which instantiats qwtPlot:
    Qt Code:
    1. QT_BEGIN_NAMESPACE
    2.  
    3. class Ui_MainWindow
    4. {
    5. public:
    6. QWidget *centralwidget;
    7. QwtPlot *qwtPlot; // here
    8. QMenuBar *menubar;
    9. QStatusBar *statusbar;
    10.  
    11. void setupUi(QMainWindow *MainWindow)
    12. {
    13. if (MainWindow->objectName().isEmpty())
    14. MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
    15. MainWindow->resize(800, 600);
    16. centralwidget = new QWidget(MainWindow);
    17. centralwidget->setObjectName(QString::fromUtf8("centralwidget"));
    18. qwtPlot = new QwtPlot(centralwidget); // here
    19. qwtPlot->setObjectName(QString::fromUtf8("qwtPlot"));
    20. qwtPlot->setGeometry(QRect(40, 30, 721, 501));
    21. MainWindow->setCentralWidget(centralwidget);
    22. menubar = new QMenuBar(MainWindow);
    23. menubar->setObjectName(QString::fromUtf8("menubar"));
    24. menubar->setGeometry(QRect(0, 0, 800, 24));
    25. MainWindow->setMenuBar(menubar);
    26. statusbar = new QStatusBar(MainWindow);
    27. statusbar->setObjectName(QString::fromUtf8("statusbar"));
    28. MainWindow->setStatusBar(statusbar);
    29.  
    30. retranslateUi(MainWindow);
    31.  
    32. QMetaObject::connectSlotsByName(MainWindow);
    33. } // setupUi
    34.  
    35. void retranslateUi(QMainWindow *MainWindow)
    36. {
    37. MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
    38. Q_UNUSED(MainWindow);
    39. } // retranslateUi
    40.  
    41. };
    42.  
    43. namespace Ui {
    44. class MainWindow: public Ui_MainWindow {};
    45. } // namespace Ui
    46.  
    47. QT_END_NAMESPACE
    To copy to clipboard, switch view to plain text mode 

    And this is the header of the M_MainWindow class I posted yesterday:
    Qt Code:
    1. class M_MainWindow : public QMainWindow,
    2. private Ui::MainWindow
    3. {
    4. Q_OBJECT
    5.  
    6. public:
    7. M_MainWindow ( QWidget *parent = 0 );
    8.  
    9. ~M_MainWindow();
    10.  
    11. };
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by kaizimir; 29th August 2009 at 10:34.

  14. #14
    Join Date
    Jul 2009
    Posts
    13
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  15. #15
    Join Date
    Oct 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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.

  16. #16
    Join Date
    Nov 2008
    Posts
    22
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11

    Default 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.

Similar Threads

  1. Replies: 21
    Last Post: 28th September 2010, 11:59
  2. Replies: 2
    Last Post: 17th June 2010, 00:58
  3. segmentation fault for no apparent reason
    By rishiraj in forum Newbie
    Replies: 1
    Last Post: 12th February 2009, 12:13
  4. Segmentation fault running any QT4 executables
    By jellis in forum Installation and Deployment
    Replies: 7
    Last Post: 19th May 2007, 17:35
  5. Icons missing => segmentation fault
    By antonio.r.tome in forum Qt Programming
    Replies: 4
    Last Post: 8th March 2006, 17:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.