在Linux上的Code :: Blocks中的一个简单的C ++测试应用程序中,我有一个名为txtSelect的wxTextCtrl,它包含:'SELECT * FROM user;'
当我运行以下内容时,请崩溃!
void refreshGrid()
{
wxTextCtrl *txtSelect;
wxString sqlLine = txtSelect->GetValue();
}
gdb结果如下:
(gdb) run
Starting program: /home/dan/Documents/wxW_Projs/wxSQLi_417/bin/Debug/wxSQLi_417
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Program received signal SIGSEGV, Segmentation fault.
0x0000000000410662 in refreshGrid ()
at /home/dan/Documents/wxW_Projs/wxSQLi_417/wxSQLi_417Main.cpp:199
199 wxString sqlLine = txtSelect->GetValue();
(gdb) bt
#0 0x0000000000410662 in refreshGrid ()
at /home/dan/Documents/wxW_Projs/wxSQLi_417/wxSQLi_417Main.cpp:199
#1 0x0000000000410593 in wxSQLi_417Frame::OnButton2Click (this=0x7143c0,
event=...)
at /home/dan/Documents/wxW_Projs/wxSQLi_417/wxSQLi_417Main.cpp:183
#2 0x00007ffff6d461fe in wxAppConsoleBase::CallEventHandler(wxEvtHandler*, wxEventFunctor&, wxEvent&) const ()
from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#3 0x00007ffff6ecc6e7 in wxEvtHandler::ProcessEventIfMatchedan(wxEventTableEntryBase const&, wxEvtHandler*, wxEvent&) ()
from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#4 0x00007ffff6eccace in wxEvtHandler::SearchDynamicEventTable(wxEvent&) ()
from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#5 0x00007ffff6eccb5f in wxEvtHandler::TryHereOnly(wxEvent&) ()
from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#6 0x00007ffff6eccc13 in wxEvtHandler::ProcessEventLocally(wxEvent&) ()
from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#7 0x00007ffff6eccc75 in wxEvtHandler::ProcessEvent(wxEvent&) ()
from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
#8 0x00007ffff75f3de8 in wxWindowBase::TryAfter(wxEvent&) ()
from /usr/lib/x86_64-linux-gnu/libwx_gtk2u_core-3.0.so.0
#9 0x00007ffff6ecc9e7 in wxEvtHandler::SafelyProcessEvent(wxEvent&) ()
from /usr/lib/x86_64-linux-gnu/libwx_baseu-3.0.so.0
---Type <return> to continue, or q <return> to quit---
我在同一台PC上有另一个应用程序,使用简单的密码演示,使用相同的简单代码并且完美运行,还有许多其他应用程序。
任何建议都非常感谢。
答案 0 :(得分:0)
txtSelect
无处可指。你应该创建一个指针所指向的对象然后使用它,如下所示:
wxTextCtrl *txtSelect = new wxTextCtrl();
wxString sqlLine = txtSelect->GetValue();
如果分配失败new
则抛出异常std::bad_alloc