question
2014-02-21 18:00
330 查看
[closed] Better to deselect the items first when we want to
clear the wxListBox items
4 | When you want to use the function "Clear" to clear all the items in the wxListBox, you had better deselect all items first(Use "DeselectAll") especially when you defined the event handle function for wxListBox. Because the "clear" function will pop up the wxEVT_COMMAND_LISTBOX_SELECTED event if you don't deselect the items first which is easy to lead to crash problem. and it will not have this problem when you deselect all first. We should use it just as follows: m_LB_Items->DeselectAll(); m_LB_Items->Clear(); wxwidgets report asked Apr 02 '13 at 18:17 bozhang 661●6●18 closed Sep 06 '13 at 10:22 rqiu 921●3●27 1 @bozhang when you defined the event handle function for wxListBox. What does this mean? (Apr 02 '13 at 18:51)Zero @bozhang, Why you said wxListBox::Clear will send that selection event? on gtk, I did not see this kind of code: 610 void wxListBox::Clear() 611 { 612 wxCHECK_RET( m_treeview != NULL, wxT("invalid listbox") ); 613 614 InvalidateBestSize(); 615 616 gtk_list_store_clear( m_liststore ); /* well, THAT was easy :) */ 617 } (Apr 02 '13 at 18:52)Zero The behavior is when there are already some items selected, then after we clear the wxListBox, it will pop up a wxEVT_COMMAND_LISTBOX_SELECTED event. we not sure whether it popped by the "clear" function or it's sub function. I will double check it. (Apr 03 '13 at 11:59)bozhang 1 for this kind of issue, I think: 1)it is best to clear to list first before you do the actual "clear" for the gui: like releasing resource. 2)write robust code, always check the validity of what you are going to operate. do not assume anything. (Apr 03 '13 at 13:48)miliao add new comment |
The question has been closed for the following reason "The question is answered, right answer was accepted" by rqiu Sep 06 '13 at 10:22
2 Answers:oldestnewestmost
voted
3 | Here is the call stack, the wxEVT_COMMAND_LISTBOX_SELECTED event is popped in the sub function of "Clear":#5 0x0000000002952451 in TflexLMCPWConditionSettingPanel::OnLbItemSelected (this=0x77c0e80) at GUI/TflexConditionSettingDlg.cpp:982 #6 0x000000000429e8db in wxAppConsole::HandleEvent (this=0x64316a0, handler=0x77c0e80, func= (void (wxEvtHandler::*)(wxEvtHandler * const, wxEvent &)) 0x2952438 <TflexLMCPWConditionSettingPanel::OnLbItemSelected(wxCommandEvent&)>, event=...) at ./src/common/appbase.cpp:322 #7 0x00000000043233cf in wxEvtHandler::ProcessEventIfMatches (entry=..., handler=0x77c0e80, event=...) at ./src/common/event.cpp:1231 #8 0x00000000043223ac in wxEventHashTable::HandleEvent (this=0x618a000 <TflexLMCPWConditionSettingPanel::sm_eventHashTable>, event=..., self=0x77c0e80) at ./src/common/event.cpp:906 #9 0x00000000043235b3 in wxEvtHandler::ProcessEvent (this=0x77c0e80, event=...) at ./src/common/event.cpp:1293 #10 0x0000000004450705 in wxWindowBase::TryParent (this=0x77eb9b0, event=...) at ./src/common/wincmn.cpp:2661 #11 0x000000000432360f in wxEvtHandler::ProcessEvent (this=0x77eb9b0, event=...) at ./src/common/event.cpp:1306 #12 0x0000000004450705 in wxWindowBase::TryParent (this=0x77f10d0, event=...) at ./src/common/wincmn.cpp:2661 #13 0x000000000432360f in wxEvtHandler::ProcessEvent (this=0x77f10d0, event=...) at ./src/common/event.cpp:1306 #14 0x0000000004450705 in wxWindowBase::TryParent (this=0x77f8b90, event=...) at ./src/common/wincmn.cpp:2661 #15 0x000000000432360f in wxEvtHandler::ProcessEvent (this=0x77f8b90, event=...) at ./src/common/event.cpp:1306 #16 0x00000000043aefa7 in gtk_listitem_changed_callback (selection=0x77f9450, listbox=0x77f8b90) at ./src/gtk/listbox.cpp:176 #17 0x00000032be10bfaa in g_closure_invoke () from /usr/lib64/libgobject-2.0.so.0 #18 0x00000032be121bf7 in ?? () from /usr/lib64/libgobject-2.0.so.0 #19 0x00000032be122cd6 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0 #20 0x00000032be122e9e in g_signal_emit_by_name () from /usr/lib64/libgobject-2.0.so.0 #21 0x00000032c01f18e1 in ?? () from /usr/lib64/libgtk-x11-2.0.so.0 #22 0x00000032be10bfaa in g_closure_invoke () from /usr/lib64/libgobject-2.0.so.0 #23 0x00000032be12152a in ?? () from /usr/lib64/libgobject-2.0.so.0 #24 0x00000032be122cd6 in g_signal_emit_valist () from /usr/lib64/libgobject-2.0.so.0 #25 0x00000032be123023 in g_signal_emit () from /usr/lib64/libgobject-2.0.so.0 #26 0x00000032c0113737 in gtk_list_store_remove () from /usr/lib64/libgtk-x11-2.0.so.0 #27 0x00000032c011420f in gtk_list_store_clear () from /usr/lib64/libgtk-x11-2.0.so.0 #28 0x00000000043b0358 in wxListBox::Clear (this=0x77f8b90) at ./src/gtk/listbox.cpp:616 #29 0x0000000002950240 in TflexLMCPWConditionSettingPanel::OnDeleteAllCondition (this=0x77c0e80, event=...) With MVC, we first clear the data in the model, then clear wxListBox with "Clear" function which will pop up a wxEVT_COMMAND_LISTBOX_SELECTED event, and in the event handle function we need to access the data in the model which is already cleared. So it leads to crash. link|award points|report answered Apr 07 '13 at 14:37 bozhang 661●6●18 @bozhang, good, so the gtk func gtk_list_store_removeemits that signal. (Apr 07 '13 at 18:49)Zero add new comment |
相关文章推荐
- RabbitMQ消息队列(三):任务分发机制
- Liger ui grid 参数
- i解决virtualbox导入vdi文件时报“uuid is exists”错误
- 关于android4.3 bluetooth4.0的那些事儿
- ios7与ios6UI风格区别
- Storyboard创建使用UICollectionViewController
- Storyboard创建使用UICollectionViewController
- UUID.randomUUID()方法介绍
- 全面解释java中StringBuilder、StringBuffer、String类之间的关系
- 全面解释java中StringBuilder、StringBuffer、String类之间的关系
- libevent源码分析-- queue.h中TAILQ_QUEUE的理解
- 给ligerui分页。
- 检测到有潜在危险的 Request.Form 值
- android反编译后value文件夹下个文件的作用解析
- UITableView整理
- uinity Animator 和Animation的正播,捯播,暂停动画实现方法(测试)
- Android Uiautomator创建过程
- easy ui 实现gridview效果
- UItableview背景透明
- Queue Implemented with LinkedList