If the thing happens when you delete the last item only, then I was experiencing a simmilar issue some time ago. Do you try to delete that item from within a slot? If so, what is the slot connected to?
If the thing happens when you delete the last item only, then I was experiencing a simmilar issue some time ago. Do you try to delete that item from within a slot? If so, what is the slot connected to?
I seems we're getting somewhere now.
The slot is connected to MainWindow. The signal is emitted from a keyboard shortcut.
The hierarchy goes:
MainWindow->Sidebar->MyListWidget
The function is:
Qt Code:
void MainWindow::NewFile() { Sidebar->MyListWidget->clear(); // Or a while loop with the following: // Sidebar->MyListWidget->takeItem(0); return; }To copy to clipboard, switch view to plain text mode
Does the application still crash if you implement it as follows:
Qt Code:
void MainWindow::NewFile(){ }To copy to clipboard, switch view to plain text mode
Yes it does
It doesn't change anything. Still crashes when something has been selected and works when nothing has.
Then it means it's not because of clear() but because of some other signal from the list widget being connected. It probably calls a slot that takes a QListWidgetItem pointer and it doesn't check for a null value and that causes a crash.
In my situation (Qt bug, AFAIR) the trick above helped. If it didn't help you, the app has to be crashing because of a null pointer in one of the slots. You can try debugging as Jacek suggested, but first I'd check the signals connected.
scwizard (24th March 2007)
Very good work!
I have a signal being emitted upon items changing and forgot to take into account that the item could change without the user changing it.
I faced Same problem, actual problem in currentRowChanged() signal's slot
I have taken one slot for currentRowChanged() signal of listwidget there i am trying to access element like following code, if we clear the list that time also that slot will be get called,so memory crash occurs,
My old code,
connect(myistWidget,SIGNAL(currentRowChanged(int)) ,this,SLOT(changeLabel(int)));
void QZugNummerDlgAction::changeLabel(int position)
{
QString labelText = myistWidget.at(position);//if we clear list memory crash occurs heremyLabel->setText(labelText);
}
New Code, i put the following condition it works properly,
void QZugNummerDlgAction::changeLabel(int position)
{
if(myistWidget->currentRow()!=-1)
{QString labelText = myistWidget.at(position);
myLabel->setText(labelText);
}
}
Thanks,
Rajesh.S
Sorry ,one mistake in my code
That is not listwidget, there i am taking one corresponding
Qlist so if we access -1 position from QList crash occurs,
that line is myqlist->at(position).
Thanks,
Rajesh.S
Bookmarks