dougbroadwell
20th March 2009, 16:10
(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.
void MainWindow::SetupHeaderWidget()
{
// Set up the ForecastHeader (database) table Model //
HeaderModel = new QSqlTableModel(this);
HeaderModel->setTable("ForecastHeader");
HeaderModel->setSort (Head_ForecastDate_Col, Qt::AscendingOrder);
HeaderModel->setHeaderData(Head_Agency_Col, Qt::Horizontal, "Agency");
HeaderModel->setHeaderData(Head_ForecastDate_Col, Qt::Horizontal, "Forecast Date");
HeaderModel->setHeaderData(Head_ForecastPercent_Col, Qt::Horizontal, "Percent");
HeaderModel->setHeaderData(Head_Note_Col, Qt::Horizontal, "Note");
HeaderModel->select(); // Suck the data into this model.
// Set up the ForecastHeader (database) table View //
--> tvForecastHeader->setModel(HeaderModel);
tvForecastHeader->setSelectionMode(QAbstractItemView::SingleSelectio n);
...
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.
void QWidget::releaseDC(HDC hdc) const
{
Q_D(const QWidget);
// If its the widgets own dc, it will be released elsewhere. If
// its a different HDC we release it and issue a warning if it
// fails.
--> if (hdc != d->hd && !ReleaseDC(winId(), hdc))
qErrnoWarning("QWidget::releaseDC(): failed to release HDC");
}
#else
...
WId QWidget::winId() const
{
if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) {
QWidget *that = const_cast<QWidget*>(this);
that->setAttribute(Qt::WA_NativeWindow);
--> that->d_func()->createWinId();
return that->data->winid;
}
return data->winid;
}
void QWidgetPrivate::createWinId(WId winid)
{
Q_Q(QWidget);
const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow);
if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) {
if (!q->isWindow()) {
QWidget *parent = q->parentWidget();
--> QWidgetPrivate *pd = parent->d_func();
if (forceNativeWindow && !q->testAttribute(Qt::WA_DontCreateNativeAncestors))
parent->setAttribute(Qt::WA_NativeWindow);
...
class Q_GUI_EXPORT QWidget : public QObject, public QPaintDevice
{
Q_OBJECT
--> Q_DECLARE_PRIVATE(QWidget)
Q_PROPERTY(bool modal READ isModal)
Q_PROPERTY(Qt::WindowModality windowModality READ windowModality WRITE setWindowModality)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
Thanks,
Doug
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.
void MainWindow::SetupHeaderWidget()
{
// Set up the ForecastHeader (database) table Model //
HeaderModel = new QSqlTableModel(this);
HeaderModel->setTable("ForecastHeader");
HeaderModel->setSort (Head_ForecastDate_Col, Qt::AscendingOrder);
HeaderModel->setHeaderData(Head_Agency_Col, Qt::Horizontal, "Agency");
HeaderModel->setHeaderData(Head_ForecastDate_Col, Qt::Horizontal, "Forecast Date");
HeaderModel->setHeaderData(Head_ForecastPercent_Col, Qt::Horizontal, "Percent");
HeaderModel->setHeaderData(Head_Note_Col, Qt::Horizontal, "Note");
HeaderModel->select(); // Suck the data into this model.
// Set up the ForecastHeader (database) table View //
--> tvForecastHeader->setModel(HeaderModel);
tvForecastHeader->setSelectionMode(QAbstractItemView::SingleSelectio n);
...
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.
void QWidget::releaseDC(HDC hdc) const
{
Q_D(const QWidget);
// If its the widgets own dc, it will be released elsewhere. If
// its a different HDC we release it and issue a warning if it
// fails.
--> if (hdc != d->hd && !ReleaseDC(winId(), hdc))
qErrnoWarning("QWidget::releaseDC(): failed to release HDC");
}
#else
...
WId QWidget::winId() const
{
if (!testAttribute(Qt::WA_WState_Created) || !internalWinId()) {
QWidget *that = const_cast<QWidget*>(this);
that->setAttribute(Qt::WA_NativeWindow);
--> that->d_func()->createWinId();
return that->data->winid;
}
return data->winid;
}
void QWidgetPrivate::createWinId(WId winid)
{
Q_Q(QWidget);
const bool forceNativeWindow = q->testAttribute(Qt::WA_NativeWindow);
if (!q->testAttribute(Qt::WA_WState_Created) || (forceNativeWindow && !q->internalWinId())) {
if (!q->isWindow()) {
QWidget *parent = q->parentWidget();
--> QWidgetPrivate *pd = parent->d_func();
if (forceNativeWindow && !q->testAttribute(Qt::WA_DontCreateNativeAncestors))
parent->setAttribute(Qt::WA_NativeWindow);
...
class Q_GUI_EXPORT QWidget : public QObject, public QPaintDevice
{
Q_OBJECT
--> Q_DECLARE_PRIVATE(QWidget)
Q_PROPERTY(bool modal READ isModal)
Q_PROPERTY(Qt::WindowModality windowModality READ windowModality WRITE setWindowModality)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
Thanks,
Doug