(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