Can QListWidget's clear() be called from a slot connected with one of its signal?
Consider this code
Code:
{
public:
SomeClass();
...
private:
};
{
}
{
if(_listWgt){
_listWgt->clear();
}
// Code to repopulate _listWgt with new list of items base on 'itemText'
// follows.
}
My code is crashing in Qt as some timer event occurs on _listWgt that perhaps has information of _listWgt before it entered onItemDoubleClicked() slot, but after this slot is done, _listWgt doesn't reflect that state.
I'm suspecting clear() as technically, it will try to delete the item on which the doubleClicked signal happened.
Can anyone agree or confirm my suspicion?
Thanks.
Re: Can QListWidget's clear() be called from a slot connected with one of its signal?
The cause of the crash could be anywhere in your program. Have you tried this suspicious pattern (calling clear() from a slot connected to itemDoubleClicked) in a minimal example?
You could also try to turn the connection into a queued one and see if this changes anything:
That way, the slot is only invoked after control has returned to the event loop.
Re: Can QListWidget's clear() be called from a slot connected with one of its signal?
Well, what does the backtrace of your crash say?
Does it still crash if you remove the call to clear()?
Cheers,
_
Re: Can QListWidget's clear() be called from a slot connected with one of its signal?
Thanks for your response guys!
The traceback in debugger was not very helpful. The real application is 20+ million lines of code, but I just extracted conceptual code. Didn't really try to create a small test program, but the issue has been resolved.
There was a 100 ms timer that would scroll the list of items to the far right automatically after the new list of items were populated. Randomly, this feature would cause the crash. See callstack below.
Code:
STACK ?
6 ? 0x64f55329
QListView::updateGeometriesSTACK ?
13 ? 0x64f54c74
QListView::updateGeometriesSTACK ?
15 ? 0x64f4a2b9
QListView::doItemsLayoutSTACK ?
17 ? 0x6a5aa5ec
QObject::eventSTACK ?
18 ? 0x64b2e913
QWidget::eventSTACK ?
19 ? 0x64e4ac97
QFrame::eventSTACK ? 21 ? 0x64af1a36 QApplicationPrivate::notify_helper
Well, just by changing the horizontal scrollbar policy to always visible instead of automatic on the QListWidget solved this issue!
This is on Qt 4.8.2 on Windows x64 MSVS 2012