Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 5

Qt-interest Archive, July 2007
QT Bug: QDataWidgetMapper, QSqlTableModel, QTableView


Message 1 in thread

Hi all,

I found a combination of QDataWidgetMapper, QSqlTableModel and 
QTableView usage, where I produce a crash on the following System

     * qt-win-commercial-4.3.0-vs2005.exe
     * qt-vsintegration-1.3.0.exe
     * Microsoft Visual C++ 2005 (Microsoft Visual Studio 2005 Version 
8.0.50727.762 (SP.050727-7600))
     * Microsoft Windows XP (Version 5.1, Build 
2600.xpsp_sp2_gdr.070227-2254 : Service Pack 2)

Run the compiled QTTEST.exe - it is a Visual Studio 2005 Solution - and 
do the following quickly (and repeat often if nothing happens the first 
time):

     * Click in "lineEdit"
     * Click in "lineEdit_2"
     * Click in "lineEdit"

In Debug-Mode, the following happens: Crash!

In Release-Mode, I get the following Output, and after a some clicks a 
crash too:

topLeft.row() = 0, bottomRight.row() = 0, widgetmapper->currentIndex() = 0
topLeft.row() = 3867048, bottomRight.row() = 3867048, 
widgetmapper->currentIndex() = 0
topLeft.row() = 0, bottomRight.row() = 0, widgetmapper->currentIndex() = 0
topLeft.row() = 0, bottomRight.row() = 0, widgetmapper->currentIndex() = 0
topLeft.row() = 0, bottomRight.row() = 0, widgetmapper->currentIndex() = 0
topLeft.row() = 3867048, bottomRight.row() = 3867048, 
widgetmapper->currentIndex() = 0
topLeft.row() = 3867104, bottomRight.row() = 3867104, 
widgetmapper->currentIndex() = 0

Please note the weird row number "3867104". I have another big project 
where exactly the same happens in Debug-Mode, but with the weird row 
number "-17891602".


Can anybody confirm?
Any workaround of patch available?

I asked the support too. If they answer I will inform you.


Regards

Niklas Hofmann

-- 
 [ signature omitted ] 

Attachment: QTTEST.zip
Description: Binary data


Message 2 in thread

Hi!

hit and sunk:
http://trolltech.com/developer/task-tracker/index_html?method=entry&id=172427
http://trolltech.com/customer/task-tracker/index_html?method=entry&id=172427

Big problem...

Regards,

Niklas Hofmann

-- 
 [ signature omitted ] 

Message 3 in thread

  Hi!

 > I can reproduce the problem, it seems to happen as a result of using
 > AutoSubmit on the QDataWidgetMapper and OnManualSubmit on the
 > QSqlTableModel.  Unfortunatly there is no easy way to workaround the
 > problem, by not having the view there, it works better since its the
 > combination of having the view and the mapper view the same model.
 > What you can do is use a QSqlQueryModel instead and update the view
 > whenever focus is lost from the mapper widgets to emulate the fact that
 > it is updating in the view too.
 >
 > I've created task 172427 for our development team. You can use this ID
 > to track the status of this task online:
 >
 > http://www.trolltech.com/developer/task-tracker
 > http://www.trolltech.com/customer/task-tracker
 >


If you put the initialisation of QDataWidgetMapper at the end, 
everything works fine:


     tablemodel = new QSqlTableModel(this, 
QSqlDatabase::database(":memory:"));
     tablemodel->setTable("person");
     tablemodel->setEditStrategy(QSqlTableModel::OnManualSubmit);
     tablemodel->select();

     ui.tableView->setModel(tablemodel);

     connect(tablemodel, SIGNAL(dataChanged(const QModelIndex&, const 
QModelIndex&)), SLOT(on_dataChanged(const QModelIndex&, const 
QModelIndex&)));

     widgetmapper = new QDataWidgetMapper(this);
     widgetmapper->setModel(tablemodel);
     widgetmapper->addMapping(ui.lineEdit, 1, "text");
     widgetmapper->addMapping(ui.lineEdit_2, 2, "text");
     widgetmapper->setSubmitPolicy(QDataWidgetMapper::AutoSubmit);
     widgetmapper->toFirst();


My guess:
The signals connected in the widgetmapper->setModel(tablemodel); are now 
called last and they probably destroy the topLeft, bottomRight 
Parameters. Therefore the bugfixing should take place somewhere in 
QDataWidgetMapper. Probably one internal slot of QDataWidgetMapper is 
responsible for the mess.


Can anybody confirm?

Best regards,

Niklas Hofmann

--
 [ signature omitted ] 

Message 4 in thread

Hi!

I think I found the culprit.. but I'm not sure how to fix this. If 
someone is able to fix this, I will pay for it (contact me via email).

The call "m.currentIndex = indexAt(m.section);" in qdatawidgetmapper.cpp 
in line 141, function "void 
QDataWidgetMapperPrivate::populate(WidgetMapper &m)" produces the mess.

If you set a breakpoint in this line, you have to do the following:

     * Stop execution at breakpoint.
     * Go back on callstack to QDataWidgetMapperPrivate::_q_dataChanged()
     * Check content of topLeft and bottomRight => everything should be ok
     * Now go back to the breakpoint
     * Execute on line of code (F10 in Visual Studio 2005)
     * Go back on callstack to QDataWidgetMapperPrivate::_q_dataChanged()
     * Check content of topLeft and bottomRight => now topLeft and 
bottomRight are invalid!!

If you have no luck the first time, check the next breakpoint hit.

The exact position, where topLeft and bottomRight get invalid is 
"qabstractitemmodel.cpp" line 85 with the call "delete data;". I have 
the following call stack in this sitation:

 
QtCored4.dll!QPersistentModelIndexData::destroy(QPersistentModelIndexData 
* data=0x00bbb6f0)  Line 86    C++
      QtCored4.dll!QPersistentModelIndex::operator=(const QModelIndex & 
other={...})  Line 224 + 0xb bytes    C++
 > 
QtGuid4.dll!QDataWidgetMapperPrivate::populate(QDataWidgetMapperPrivate::WidgetMapper 
& m={...})  Line 141 + 0x33 bytes    C++
      QtGuid4.dll!QDataWidgetMapperPrivate::_q_dataChanged(const 
QModelIndex & topLeft={...}, const QModelIndex & bottomRight={...}) 
Line 170    C++
      QtGuid4.dll!QDataWidgetMapper::qt_metacall(QMetaObject::Call 
_c=InvokeMetaMethod, int _id=9, void * * _a=0x0012b6e0)  Line 110 + 0x1d 
bytes    C++
      QtCored4.dll!QMetaObject::activate(QObject * sender=0x00bbbd58, 
int from_signal_index=4, int to_signal_index=4, void * * 
argv=0x0012b6e0)  Line 3064 + 0x46 bytes    C++
      QtCored4.dll!QMetaObject::activate(QObject * sender=0x00bbbd58, 
const QMetaObject * m=0x672041c4, int local_signal_index=0, void * * 
argv=0x0012b6e0)  Line 3123 + 0x15 bytes    C++
      QtCored4.dll!QAbstractItemModel::dataChanged(const QModelIndex & 
_t1={...}, const QModelIndex & _t2={...})  Line 123 + 0x14 bytes    C++
      QtSqld4.dll!QSqlTableModel::setData(const QModelIndex & 
index={...}, const QVariant & value={...}, int role=2)  Line 545    C++
      QtGuid4.dll!QDataWidgetMapperPrivate::commit(const 
QDataWidgetMapperPrivate::WidgetMapper & m={...})  Line 131 + 0x57 bytes 
    C++
      QtGuid4.dll!QDataWidgetMapperPrivate::_q_commitData(QWidget * 
w=0x00ba7328)  Line 183    C++
      QtGuid4.dll!QDataWidgetMapper::qt_metacall(QMetaObject::Call 
_c=InvokeMetaMethod, int _id=10, void * * _a=0x0012bc98)  Line 111 + 
0x18 bytes    C++
      QtCored4.dll!QMetaObject::activate(QObject * sender=0x00bbd820, 
int from_signal_index=4, int to_signal_index=4, void * * 
argv=0x0012bc98)  Line 3064 + 0x46 bytes    C++
      QtCored4.dll!QMetaObject::activate(QObject * sender=0x00bbd820, 
const QMetaObject * m=0x65933258, int local_signal_index=0, void * * 
argv=0x0012bc98)  Line 3123 + 0x15 bytes    C++
      QtGuid4.dll!QAbstractItemDelegate::commitData(QWidget * 
_t1=0x00ba7328)  Line 90 + 0x15 bytes    C++
      QtGuid4.dll!QItemDelegate::eventFilter(QObject * 
object=0x00ba7328, QEvent * event=0x0012c08c)  Line 1177    C++
      QtGuid4.dll!QApplicationPrivate::notify_helper(QObject * 
receiver=0x00ba7328, QEvent * e=0x0012c08c)  Line 3528 + 0x1b bytes    C++
      QtGuid4.dll!QApplication::notify(QObject * receiver=0x00ba7328, 
QEvent * e=0x0012c08c)  Line 3477 + 0x10 bytes    C++
      QtCored4.dll!QCoreApplication::notifyInternal(QObject * 
receiver=0x00ba7328, QEvent * event=0x0012c08c)  Line 508    C++
      QtCored4.dll!QCoreApplication::sendEvent(QObject * 
receiver=0x00ba7328, QEvent * event=0x0012c08c)  Line 184 + 0x39 bytes 
   C++
      QtGuid4.dll!QApplicationPrivate::setFocusWidget(QWidget * 
focus=0x00ba7388, Qt::FocusReason reason=MouseFocusReason)  Line 1878 + 
0xe bytes    C++
      QtGuid4.dll!QWidget::setFocus(Qt::FocusReason 
reason=MouseFocusReason)  Line 4425 + 0xd bytes    C++
      QtGuid4.dll!QApplication::notify(QObject * receiver=0x00ba7388, 
QEvent * e=0x0012c4f0)  Line 3189    C++
      QtCored4.dll!QCoreApplication::notifyInternal(QObject * 
receiver=0x00ba7388, QEvent * event=0x0012c4f0)  Line 508    C++
      QtCored4.dll!QCoreApplication::sendSpontaneousEvent(QObject * 
receiver=0x00ba7388, QEvent * event=0x0012c4f0)  Line 187 + 0x38 bytes 
   C++
      QtGuid4.dll!QETWidget::translateMouseEvent(const tagMSG & 
msg={...})  Line 2744 + 0x14 bytes    C++
      QtGuid4.dll!QtWndProc(HWND__ * hwnd=0x001b0f08, unsigned int 
message=513, unsigned int wParam=1, long lParam=852058)  Line 1376 + 0xc 
bytes    C++
      user32.dll!7e418734()
      [Frames below may be incorrect and/or missing, no symbols loaded 
for user32.dll]
      user32.dll!7e418816()
      user32.dll!7e4189cd()
      user32.dll!7e418a10()
      QtCored4.dll!QEventDispatcherWin32::processEvents(QFlags<enum 
QEventLoop::ProcessEventsFlag> flags={...})  Line 519 + 0x18 bytes    C++
      QtGuid4.dll!QGuiEventDispatcherWin32::processEvents(QFlags<enum 
QEventLoop::ProcessEventsFlag> flags={...})  Line 963 + 0x15 bytes    C++
      QtCored4.dll!QEventLoop::processEvents(QFlags<enum 
QEventLoop::ProcessEventsFlag> flags={...})  Line 125    C++
      QtCored4.dll!QEventLoop::exec(QFlags<enum 
QEventLoop::ProcessEventsFlag> flags={...})  Line 170 + 0x2d bytes    C++
      QtCored4.dll!QCoreApplication::exec()  Line 727 + 0x15 bytes    C++
      QtGuid4.dll!QApplication::exec()  Line 3034    C++
      QTTEST.exe!main(int argc=1, char * * argv=0x003b6780)  Line 10 + 
0x6 bytes    C++
      QTTEST.exe!WinMain(HINSTANCE__ * instance=0x00400000, HINSTANCE__ 
* prevInstance=0x00000000, char * __formal=0x00151f44, int cmdShow=1) 
Line 103 + 0x12 bytes    C++
      QTTEST.exe!__tmainCRTStartup()  Line 589 + 0x35 bytes    C
      QTTEST.exe!WinMainCRTStartup()  Line 414    C
      kernel32.dll!7c816fd7()


Is it possible to find a patch for this?

If someone is able to fix this, I will pay for it.

Greetings

Niklas Hofmann

-- 
 [ signature omitted ] 

Message 5 in thread

Hi!

 > I found a combination of QDataWidgetMapper, QSqlTableModel and
 > QTableView usage, where I produce a crash on the following System
 >

we implemented our own DataWidgetMapper and it works well now...
If someone is interested in the code, just contact me via email.

Greetings

Niklas

--
 [ signature omitted ]