Results 1 to 3 of 3

Thread: Unhandled Exception

  1. #1
    Join Date
    Dec 2007
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Unhandled Exception

    (Reposted with code inserted)

    Windows, Qt Creator 1.0.0, Qt 4.5.0

    I'm creating a little SQL input form. In the main window constructor, I create a QSqlTableModel and when I try to associate it with a QTableView created in QDesigner I get the runtime error:

    Unhandled exception at 0x00f8a5be in Forecast1.exe: 0xC0000005: Access violation reading location 0x00000004

    The arrow in the following code is where it is occurring.

    Qt Code:
    1. void MainWindow::SetupHeaderWidget()
    2. {
    3. // Set up the ForecastHeader (database) table Model //
    4.  
    5. HeaderModel = new QSqlTableModel(this);
    6. HeaderModel->setTable("ForecastHeader");
    7. HeaderModel->setSort (Head_ForecastDate_Col, Qt::AscendingOrder);
    8. HeaderModel->setHeaderData(Head_Agency_Col, Qt::Horizontal, "Agency");
    9. HeaderModel->setHeaderData(Head_ForecastDate_Col, Qt::Horizontal, "Forecast Date");
    10. HeaderModel->setHeaderData(Head_ForecastPercent_Col, Qt::Horizontal, "Percent");
    11. HeaderModel->setHeaderData(Head_Note_Col, Qt::Horizontal, "Note");
    12. HeaderModel->select(); // Suck the data into this model.
    13.  
    14. // Set up the ForecastHeader (database) table View //
    15.  
    16. --> tvForecastHeader->setModel(HeaderModel);
    17. tvForecastHeader->setSelectionMode(QAbstractItemView::SingleSelection);
    18. ...
    To copy to clipboard, switch view to plain text mode 

    In running in the debugger traces it to the lines below, at (in qwidget.h line 144):

    QWidgetPrivate *pd = parent->d_func();

    is where it happens, when I step a message displayed is: ' stopped: "signal received" ' and the debugger will not go beyond the "Q_DECLARE_PRIVATE(QWidget)" line in the last section.
    Qt Code:
    1. void QWidget::releaseDC(HDC hdc) const
    2. {
    3. Q_D(const QWidget);
    4. // If its the widgets own dc, it will be released elsewhere. If
    5. // its a different HDC we release it and issue a warning if it
    6. // fails.
    7. --> if (hdc != d->hd && !ReleaseDC(winId(), hdc))
    8. qErrnoWarning("QWidget::releaseDC(): failed to release HDC");
    9. }
    10. #else
    11. ...
    12.  
    13.  
    14. WId QWidget::winId() const
    15. {
    16. if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) {
    17. QWidget *that = const_cast<QWidget*>(this);
    18. that->setAttribute(Qt::WA_NativeWindow);
    19. --> that->d_func()->createWinId();
    20. return that->data->winid;
    21. }
    22. return data->winid;
    23. }
    24.  
    25.  
    26. void QWidgetPrivate::createWinId(WId winid)
    27. {
    28. Q_Q(QWidget);
    29. const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow);
    30. if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) {
    31. if (!q->isWindow()) {
    32. QWidget *parent = q->parentWidget();
    33. --> QWidgetPrivate *pd = parent->d_func();
    34. if (forceNativeWindow && !q->testAttribute(Qt::WA_DontCreateNativeAncestors))
    35. parent->setAttribute(Qt::WA_NativeWindow);
    36. ...
    37.  
    38.  
    39. class Q_GUI_EXPORT QWidget : public QObject, public QPaintDevice
    40. {
    41. Q_OBJECT
    42. --> Q_DECLARE_PRIVATE(QWidget)
    43. Q_PROPERTY(bool modal READ isModal)
    44. Q_PROPERTY(Qt::WindowModality windowModality READ windowModality WRITE setWindowModality)
    45. Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
    To copy to clipboard, switch view to plain text mode 

    Thanks,
    Doug

  2. #2
    Join Date
    Dec 2007
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unhandled Exception

    Another Datapoint:

    I'm using multiple inheritance to use graphic objects generated from QDesigner, in this case in the file ui_mainwindow.h (I have used the multiple inheritance approach in other projects without experiencing this problem). If I replace the:

    Qt Code:
    1. tvForecastHeader->setModel(HeaderModel);
    To copy to clipboard, switch view to plain text mode 

    where tvForecastHeader is created in the object defined in ui_mainwindow.h and instantiated in the mainwindow constructor:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindowClass)
    2. {
    3. ui->setupUi(this);
    4. ...
    To copy to clipboard, switch view to plain text mode 

    with a locally created one as in:

    Qt Code:
    1. DetailView = new QTableView();
    2. DetailView->setModel(HeaderModel);
    To copy to clipboard, switch view to plain text mode 

    It doesn't crash. But I can't see what's different from this and the instatiation in MainWindowObject.

    ?? Doug

  3. #3
    Join Date
    Dec 2007
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Unhandled Exception

    Well, I switched from using the Multiple Inheritance method to the Single Inheritance method and now it works !?!?!

    So I'll consider this a fix for now but would sure like to know if I was doing something wrong or if it was a bug.

    Regards,
    Doug

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Unhandled Exception in QTableView->setModel(QSqlTableModel)
    By dougbroadwell in forum Qt Programming
    Replies: 0
    Last Post: 19th March 2009, 19:35
  3. Replies: 3
    Last Post: 27th January 2009, 09:31
  4. Unhandled Exception Err
    By Masih in forum Newbie
    Replies: 9
    Last Post: 25th July 2007, 20:28
  5. Exceptions and qApp->processEvents()
    By mcostalba in forum Qt Programming
    Replies: 3
    Last Post: 8th January 2006, 17:06

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.