Results 1 to 4 of 4

Thread: Weird Segfault...

  1. #1

    Default Weird Segfault...

    I am not the best at debugging yet, so I am struggling to figure this one out. I am trying to use a custom class based on QTableView. It compiles ok, but when I try to run the program I get the following segfault:

    [Thread debugging using libthread_db enabled]
    [New Thread 0xb67e86c0 (LWP 23223)]
    [New Thread 0xb5b97b90 (LWP 23226)]
    [Thread 0xb5b97b90 (LWP 23226) exited]

    Program received signal SIGSEGV, Segmentation fault.
    [Switching to Thread 0xb67e86c0 (LWP 23223)]
    0xb77477fd in QWidget::~QWidget () from /usr/lib/libQtGui.so.4
    I don't really know where to start... here is my super simple subclassed QTableView...

    Qt Code:
    1. #ifndef APPOINTMENTBOOK_H
    2. #define APPOINTMENTBOOK_H
    3.  
    4. #include <QtCore>
    5. #include <QTableView>
    6.  
    7. class AppointmentBook : public QTableView
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. AppointmentBook(QWidget *parent = 0);
    13.  
    14. protected:
    15. void paintEvent(QPaintEvent *event);
    16.  
    17. };
    18.  
    19. #endif
    To copy to clipboard, switch view to plain text mode 

    and the cpp...

    Qt Code:
    1. #include <QtGui>
    2. #include <QTableView>
    3. #include "appointmentbook.h"
    4.  
    5. AppointmentBook::AppointmentBook(QWidget *parent)
    6. : QTableView(parent)
    7. {
    8. //QTimer *timer = new QTimer(this);
    9. //connect(timer, SIGNAL(timeout()), this, SLOT(update()));
    10. //timer->start(1000);
    11.  
    12. //setWindowTitle(tr("Appointment Book"));
    13. //resize(200, 200);
    14.  
    15. }
    16.  
    17. void AppointmentBook::paintEvent(QPaintEvent *)
    18. {
    19.  
    20. //QColor secondColor(208, 22, 13, 255);
    21.  
    22. //QTime time = QTime::currentTime();
    23.  
    24. //QPainter painter(this);
    25. //painter.setRenderHint(QPainter::Antialiasing);
    26. //painter.scale(width(), height() / 86400.0);
    27.  
    28. //painter.setPen(Qt::NoPen);
    29.  
    30.  
    31. //painter.setPen(secondColor);
    32.  
    33. //int lineY = (time.hour()*60*60) + (time.minute()*60) + time.second();
    34. //painter.drawLine(0, lineY, width(), lineY);
    35.  
    36. }
    To copy to clipboard, switch view to plain text mode 

    As you can see it is all commented out because I can't figure out what's going on.

  2. #2
    Join Date
    Jan 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Weird Segfault...

    I copied and pasted your code and created a simple test program to verify your segfault

    Qt Code:
    1. #include <QHBoxLayout>
    2. #include <QWidget>
    3. #include <QApplication>
    4. #include "appointmentbook.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. QWidget *window = new QWidget;
    11. AppointmentBook *view = new AppointmentBook();
    12. QHBoxLayout *layout = new QHBoxLayout;
    13. layout->addWidget(view);
    14.  
    15. window->setLayout(layout);
    16. window->show();
    17.  
    18. return a.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

    And it runs perfectly fine. How are you trying to use AppointmentBook is your app? I suspect your segfault is somewhere else.

    You might try commenting out more and more of your code until it works and then add it all back in until it crashes again. qDebug() lines are also good for trying to find the problem.

  3. #3

    Default Re: Weird Segfault...

    OK I've narrowed it down a bit. It only segfaults when I set the model. I have subclassed QAbstractTableModel

    Qt Code:
    1. #ifndef CALENDARDAYMODEL_H
    2. #define CALENDARDAYMODEL_H
    3.  
    4. #include <QtCore>
    5. #include <QAbstractTableModel>
    6. #include <QList>
    7.  
    8. class CalendarDayModel : public QAbstractTableModel
    9. {
    10.  
    11. public:
    12.  
    13. CalendarDayModel(QObject *parent = 0);
    14.  
    15. int rowCount(const QModelIndex &parent = QModelIndex()) const;
    16. int columnCount(const QModelIndex &parent) const;
    17. Qt::ItemFlags flags(){}
    18. QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
    19. QVariant data(const QModelIndex &index, int role) const;
    20.  
    21. private:
    22. QList<QString> vert12Hours;
    23. QList<QString> vertHeader;
    24. QList<QString> horizHeader;
    25.  
    26. };
    27.  
    28. #endif // CALENDARDAYMODEL_H
    To copy to clipboard, switch view to plain text mode 

    and cpp...

    Qt Code:
    1. #include "calendardaymodel.h"
    2.  
    3. CalendarDayModel::CalendarDayModel(QObject *parent)
    4. {
    5. vert12Hours.append(QString("12am"));
    6. vert12Hours.append(QString("1am"));
    7. vert12Hours.append(QString("2am"));
    8. vert12Hours.append(QString("3am"));
    9. vert12Hours.append(QString("4am"));
    10. vert12Hours.append(QString("5am"));
    11. vert12Hours.append(QString("6am"));
    12. vert12Hours.append(QString("7am"));
    13. vert12Hours.append(QString("8am"));
    14. vert12Hours.append(QString("9am"));
    15. vert12Hours.append(QString("10am"));
    16. vert12Hours.append(QString("11am"));
    17. vert12Hours.append(QString("12pm"));
    18. vert12Hours.append(QString("1pm"));
    19. vert12Hours.append(QString("2pm"));
    20. vert12Hours.append(QString("3pm"));
    21. vert12Hours.append(QString("4pm"));
    22. vert12Hours.append(QString("5pm"));
    23. vert12Hours.append(QString("6pm"));
    24. vert12Hours.append(QString("7pm"));
    25. vert12Hours.append(QString("8pm"));
    26. vert12Hours.append(QString("9pm"));
    27. vert12Hours.append(QString("10pm"));
    28. vert12Hours.append(QString("11pm"));
    29. int i;
    30. for(i=0;i<vert12Hours.count();i++)
    31. {
    32. vertHeader.append(vert12Hours.at(i));
    33. vertHeader.append(QString(" :10"));
    34. vertHeader.append(QString(" :20"));
    35. vertHeader.append(QString(" :30"));
    36. vertHeader.append(QString(" :40"));
    37. vertHeader.append(QString(" :50"));
    38. }
    39. }
    40.  
    41. int CalendarDayModel::rowCount(const QModelIndex &parent) const
    42. {
    43. //return vertHeader.count();
    44. return 1;
    45. }
    46.  
    47. int CalendarDayModel::columnCount(const QModelIndex &parent) const
    48. {
    49. return 2;
    50. }
    51.  
    52. QVariant CalendarDayModel::headerData(int section, Qt::Orientation orientation, int role) const
    53. {
    54. if (role != Qt::DisplayRole)
    55. return QVariant();
    56. if (orientation == Qt::Horizontal)
    57. {
    58. return QString("OR");
    59. }
    60. else
    61. {
    62. return vertHeader.at(section);
    63. }
    64. }
    65.  
    66. QVariant CalendarDayModel::data(const QModelIndex &index, int role) const
    67. {
    68. if (!index.isValid())
    69. return QVariant();
    70. if (index.row() < 0 || index.row() >= 10)
    71. return QVariant();
    72. if (role == Qt::DisplayRole)
    73. return "test";
    74. return QVariant();
    75. }
    To copy to clipboard, switch view to plain text mode 

    I try to set the model by...

    Qt Code:
    1. //Load Default Appointment Book
    2. QAbstractTableModel *model = new CalendarDayModel;
    3. calViewTable->setModel(model);
    To copy to clipboard, switch view to plain text mode 

    and that is when it segfaults.

  4. #4

    Default Re: Weird Segfault...

    Anyone? I am all out of ideas.

    thanks.

Similar Threads

  1. Segfault in Construkctor of QCoreApplication?!?
    By schulze in forum Qt Programming
    Replies: 1
    Last Post: 6th November 2008, 11:50
  2. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  3. Segfault
    By Dumbledore in forum Qt Programming
    Replies: 3
    Last Post: 12th November 2007, 07:31
  4. Weird behaviour of mouse events and QMenu pop-ups
    By Ishark in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 07:46
  5. segfault
    By conexion2000 in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2006, 12:34

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.