[Qt-jambi-interest] Problem with QItemDelegate signal connection
Mathias
listo.mathias at googlemail.com
Thu Feb 19 11:07:18 CET 2009
Gentlemen,
I have a strange problem that looks like a bug to me.
Consider this short piece of test code:
public class SignalConnectionTest extends QTreeView {
private static boolean fired;
@Override
protected void closeEditor(QWidget widget,
QAbstractItemDelegate.EndEditHint hint) {
fired = true;
}
public static void main(String[] args) {
QApplication.initialize(args);
QTreeView treeView = new SignalConnectionTest();
treeView.setItemDelegate(new QItemDelegate());
// when the following line is enabled the test works as expected
// treeView.itemDelegate().closeEditor.connect(treeView,
"closeEditor(QWidget, QAbstractItemDelegate$EndEditHint)");
treeView.itemDelegate().closeEditor.emit(treeView,
QAbstractItemDelegate.EndEditHint.NoHint);
System.out.println(fired); // expected printout: "true"
QApplication.instance().dispose();
}
}
>From how I understand the documentation and the C++ source any
QAbstractItemView should automatically hook up its closeEditor() slot (and
two others) to the respective signals in any newly set
QAbstractItemDelegate.
However, for some reason in Jambi it doesn't.
I have to manually hook up the signal slot connection.
How come?
Cheers,
Mathias
PS: The respective C++ source looks very simple:
void QAbstractItemView::setItemDelegate(QAbstractItemDelegate *delegate)
{
Q_D(QAbstractItemView);
if (delegate == d->itemDelegate)
return;
if (d->itemDelegate) {
if (d->delegateRefCount(d->itemDelegate) == 1) {
disconnect(d->itemDelegate,
SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)),
this,
SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)));
disconnect(d->itemDelegate, SIGNAL(commitData(QWidget*)), this,
SLOT(commitData(QWidget*)));
disconnect(d->itemDelegate,
SIGNAL(sizeHintChanged(QModelIndex)), this, SLOT(doItemsLayout()));
}
}
if (delegate) {
if (d->delegateRefCount(delegate) == 0) {
connect(delegate,
SIGNAL(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)),
this,
SLOT(closeEditor(QWidget*,QAbstractItemDelegate::EndEditHint)));
connect(delegate, SIGNAL(commitData(QWidget*)), this,
SLOT(commitData(QWidget*)));
qRegisterMetaType<QModelIndex>("QModelIndex");
connect(delegate, SIGNAL(sizeHintChanged(QModelIndex)), this,
SLOT(doItemsLayout()), Qt::QueuedConnection);
}
}
d->itemDelegate = delegate;
}
The new delegate is correctly being set so the last line is being executed,
which means the only problem can be the delegateRefCount() call, no?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-jambi-interest/attachments/20090219/e57b0480/attachment.html
More information about the Qt-jambi-interest
mailing list