Solved Issues about the function of remove() and clear() from QMap
-
Hi, I try to use buttons to delete all of the items in QMap. So I use the function of clear() from QMap. But when I click the button, the program exits abnormally. What happened to this?
void MainWindow::Btn_Read_Click(){ if(Component_List[Button_Index-1].Button_Read->text() == tr("Stop")){ port->PauseRead(); } }
.h file
QMap<int, QByteArray> m_writeData;
void Serial_Service::PauseRead() { qDebug()<<"pause"; /* qDeleteAll(m_writeData.begin(),m_writeData.end());*/ m_writeData.clear(); m_timer->stop(); }
-
As always - use a debugger and see where it crashes.
-
@Yandong-Luo debug output shows some print "data : ..... length : 9" it means crashing is not happening due to map.clear()/PauseRead().
Use debugger to locate the crash -
@nagesh @Christian-Ehrlicher Thanks for your help! I use debugger to locate the crash and I found the program will run to this function and then crash. I still don't know what happens. if I don't use clear(), the program will not crash.
-
Does m_Writedata map object being used in any thread during clear operation?
-
@nagesh Really Thanks for your help. I solved it!