I am making a crossplatform c++ wxwidgets desktop app, and I got a problem on Windows,…
- User
I am making a crossplatform c++ wxwidgets desktop app, and I got a problem on Windows, Linux works perfectly. I have a method that detects if a wxCombobox was edited and then do something. The problem on Windows is that it calls this method as soon as the frame is loaded and the wxCombobox was initialized with the initial value, where on Linux it doesn’t call it.
The method is this: void Frame::OnCombobox(wxCommandEvent& event) { if ((event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED || event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED) && event.GetSelection() != wxNOT_FOUND) { SetEdited(); }
event.Skip(); }
And the callstack is this: #0 ?? Frame::OnCombobox (this=0x2ba5ff0, event=…) #1 0x698c3946 wxAppConsoleBase::HandleEvent(this=0x2b63490, handler=0x2ba5ff0, func=&virtual table offset 2232, event=…) (…/…/src/common/appbase.cpp:657) #2 0x698c39c7 wxAppConsoleBase::CallEventHandler(this=0x2b63490, handler=0x2ba5ff0, functor=…, event=…) (…/…/src/common/appbase.cpp:669) #3 0x6999a7d2 wxEvtHandler::ProcessEventIfMatchesId(entry=…, handler=0x2ba5ff0, event=…) (…/…/src/common/event.cpp:1425) #4 0x6999b4e8 wxEvtHandler::SearchDynamicEventTable(this=0x2ba79b0, event=…) (…/…/src/common/event.cpp:1897) #5 0x6999ac45 wxEvtHandler::TryHereOnly(this=0x2ba79b0, event=…) (…/…/src/common/event.cpp:1618) #6 0x699ddc6c wxEvtHandler::TryBeforeAndHere(this=0x2ba79b0, event=…) (…/…/include/wx/event.h:3927) #7 0x6999aaca wxEvtHandler::ProcessEventLocally(this=0x2ba79b0, event=…) (…/…/src/common/event.cpp:1555) #8 0x6999aa66 wxEvtHandler::ProcessEvent(this=0x2ba79b0, event=…) (…/…/src/common/event.cpp:1528) #9 0x6999ad36 wxEvtHandler::SafelyProcessEvent(this=0x2ba79b0, event=…) (…/…/src/common/event.cpp:1646) #10 0x6cf56f0a wxWindowBase::HandleWindowEvent(this=0x2ba79b0, event=…) (…/…/src/common/wincmn.cpp:1570)
- Assistant
Based on the provided code and call stack, it seems that the issue occurs on Windows where the
OnComboboxmethod is called as soon as the frame is loaded, even if the combobox was not manually edited.To fix this issue, you can modify the code to handle only events that indicate that the combobox was actually edited by the user. One way to do this is by checking if the combobox value has changed since initialization. Here's an example of how you can modify the
OnComboboxmethod to address this issue:void Frame::OnCombobox(wxCommandEvent& event) { static bool initialized = false; if (initialized && (event.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED || event.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED) && event.GetSelection() != wxNOT_FOUND) { SetEdited(); } event.Skip(); initialized = true; }In this modified code, a static boolean variable
initializedis used to track whether the combobox has been initialized or not. The method will only be called if is and the event type indicates that the combobox was edited. The flag is set to after the first event is processed, preventing the method from being called when the combobox is initially loaded.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.