CodeBlocks wxWidgets没有wxGrid

问题描述

我正在尝试在wxWidgets项目中创建一个wxGrid。由于某种原因,尽管有关wxWidgets的其他所有内容似乎都可以正常工作,但它无法正常工作。就像我不确定wxWidgets安装不支持wxGrid一样。

当我创建一个基本程序时,它可以正常工作。例如,当我使用wxWidgets目录中的最小示例创建最小项目时,它运行良好,并显示消息对话框。但是,当我将其添加到顶部时:

#include <wx/grid.h>

这到框架构造函数的结尾

// Create a wxGrid object
wxGrid *grid = new wxGrid(this,wxID_ANY,wxDefaultPosition,wxSize(400,300));

// Then we call CreateGrid to set the dimensions of the grid
// (8 rows and 10 columns in this example)
grid->CreateGrid(8,10);

// We can set the sizes of individual rows and columns
// in pixels
grid->SetRowSize(0,60);
grid->SetColSize(0,120 );

// And set grid cell contents as strings
grid->SetCellValue(0,wxT("wxGrid is good"));

// We can specify that some cells are read-only
grid->SetCellValue(0,3,wxT("This is read-only"));
grid->SetReadOnly(0,3);

// Colors can be specified for grid cell contents
grid->SetCellValue(3,wxT("green on grey"));
grid->SetCellTextColour(3,*wxGREEN);
grid->SetCellBackgroundColour(3,*wxLIGHT_GREY);

// We can specify that some cells will store numeric
// values rather than strings. Here we set grid column 5
// to hold floating point values displayed with width of 6
// and precision of 2
grid->SetColFormatFloat(5,6,2);
grid->SetCellValue(0,wxT("3.1415"));

// Set the grid size to the minimum required to show the content
grid->Fit();

// Set the parent frame client size to fit the grid
this->SetClientSize(grid->GetSize());

当我尝试构建时,它停在行上

grid->CreateGrid(8,10);

并在构建日志中说:

||=== Build: Debug in minimal (compiler: GNU GCC Compiler) ===|
obj\Debug\minimal.o||In function `MyFrame::MyFrame(wxString const&)':|
C:\Users\Geoff\Desktop\minimal\minimal.cpp|187|undefined reference to `wxGrid::CreateGrid(int,int,wxGrid::wxGridSelectionModes)'|
C:\Users\Geoff\Desktop\minimal\minimal.cpp|191|undefined reference to `wxGrid::SetRowSize(int,int)'|
C:\Users\Geoff\Desktop\minimal\minimal.cpp|192|undefined reference to `wxGrid::SetColSize(int,int)'|
C:\Users\Geoff\Desktop\minimal\minimal.cpp|195|undefined reference to `wxGrid::SetCellValue(int,wxString const&)'|
C:\Users\Geoff\Desktop\minimal\minimal.cpp|198|undefined reference to `wxGrid::SetCellValue(int,wxString const&)'|
C:\Users\Geoff\Desktop\minimal\minimal.cpp|199|undefined reference to `wxGrid::SetReadOnly(int,bool)'|
C:\Users\Geoff\Desktop\minimal\minimal.cpp|202|undefined reference to `wxGrid::SetCellValue(int,wxString const&)'|
C:\Users\Geoff\Desktop\minimal\minimal.cpp|203|undefined reference to `wxGrid::SetCellTextColour(int,wxColour const&)'|
C:\Users\Geoff\Desktop\minimal\minimal.cpp|204|undefined reference to `wxGrid::SetCellBackgroundColour(int,wxColour const&)'|
C:\Users\Geoff\Desktop\minimal\minimal.cpp|210|undefined reference to `wxGrid::SetColFormatFloat(int,int)'|
C:\Users\Geoff\Desktop\minimal\minimal.cpp|211|undefined reference to `wxGrid::SetCellValue(int,wxString const&)'|
obj\Debug\minimal.o||In function `wxGrid::wxGrid(wxWindow*,wxPoint const&,wxSize const&,long,wxString const&)':|
C:\Users\Geoff\Desktop\wxWidgets-3.0.5\include\wx\generic\grid.h|944|undefined reference to `wxGrid::Init()'|
C:\Users\Geoff\Desktop\wxWidgets-3.0.5\include\wx\generic\grid.h|946|undefined reference to `wxGrid::Create(wxWindow*,wxString const&)'|
obj\Debug\minimal.o:minimal.cpp:(.rdata$.refptr.wxGridNameStr[.refptr.wxGridNameStr]+0x0)||undefined reference to `wxGridNameStr'|
obj\Debug\minimal.o:minimal.cpp:(.rdata$.refptr._ZTV6wxGrid[.refptr._ZTV6wxGrid]+0x0)||undefined reference to `vtable for wxGrid'|
||error: ld returned 1 exit status|
||=== Build Failed: 16 error(s),0 warning(s) (0 minute(s),2 second(s)) ===|

我不明白,因为我已经在CodeBlocks中使用wxWidgets已有几个月了,并且从未遇到使用任何类型控件的问题。我在顶部包括网格。而且它并没有停止在我声明网格的那一行,问题开始于CreateGrid

此外,如果我尝试使用wxSmith构建器创建wxWidgets项目,则当我尝试向框架添加网格时,程序崩溃,并弹出消息:

enter image description here

我在做什么错了?

这是我要运行的完整的minimal.cpp文件

// For compilers that support precompilation,includes "wx/wx.h".
#include "wx/wxprec.h"

// ADDED BY ME
#include <wx/grid.h>

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others,include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
    #include "wx/wx.h"
#endif


// the application icon (under Windows and OS/2 it is in resources and even
// though we Could still include the XPM here it would be unused)
#ifndef wxHAS_IMAGES_IN_RESOURCES
    #include "../sample.xpm"
#endif


// Define a new application type,each program should derive a class from wxApp
class MyApp : public wxApp
{
public:
    // override base class virtuals
    // ----------------------------

    // this one is called on application startup and is a good place for the app
    // initialization (doing it here and not in the ctor allows to have an error
    // return: if OnInit() returns false,the application terminates)
    virtual bool OnInit();
};

// Define a new frame type: this is going to be our main frame
class MyFrame : public wxFrame
{
public:
    // ctor(s)
    MyFrame(const wxString& title);

    // event handlers (these functions should _not_ be virtual)
    void OnQuit(wxCommandEvent& event);
    void OnAbout(wxCommandEvent& event);

private:
    // any class wishing to process wxWidgets events must use this macro
    wxDECLARE_EVENT_TABLE();
};

// IDs for the controls and the menu commands
enum
{
    // menu items
    Minimal_Quit = wxID_EXIT,// it is important for the id corresponding to the "About" command to have
    // this standard value as otherwise it won't be handled properly under Mac
    // (where it is special and put into the "Apple" menu)
    Minimal_About = wxID_ABOUT
};


// the event tables connect the wxWidgets events with the functions (event
// handlers) which process them. It can be also done at run-time,but for the
// simple menu events like this the static method is much simpler.
wxBEGIN_EVENT_TABLE(MyFrame,wxFrame)
    EVT_MENU(Minimal_Quit,MyFrame::OnQuit)
    EVT_MENU(Minimal_About,MyFrame::OnAbout)
wxEND_EVENT_TABLE()

// Create a new application object: this macro will allow wxWidgets to create
// the application object during program execution (it's better than using a
// static object for many reasons) and also implements the accessor function
// wxGetApp() which will return the reference of the right type (i.e. MyApp and
// not wxApp)
IMPLEMENT_APP(MyApp)


// 'Main program' equivalent: the program execution "starts" here
bool MyApp::OnInit()
{
    // call the base class initialization method,currently it only parses a
    // few common command-line options but it Could be do more in the future
    if ( !wxApp::OnInit() )
        return false;

    // create the main application window
    MyFrame *frame = new MyFrame("Minimal wxWidgets App");

    // and show it (the frames,unlike simple controls,are not shown when
    // created initially)
    frame->Show(true);

    // success: wxApp::OnRun() will be called which will enter the main message
    // loop and the application will run. If we returned false here,the
    // application would exit immediately.
    return true;
}


// frame constructor
MyFrame::MyFrame(const wxString& title)
       : wxFrame(NULL,title)
{
    // set the frame icon
    SetIcon(wxICON(sample));

#if wxUSE_MENUS
    // create a menu bar
    wxMenu *fileMenu = new wxMenu;

    // the "About" item should be in the help menu
    wxMenu *helpMenu = new wxMenu;
    helpMenu->Append(Minimal_About,"&About\tF1","Show about dialog");

    fileMenu->Append(Minimal_Quit,"E&xit\tAlt-X","Quit this program");

    // Now append the freshly created menu to the menu bar...
    wxMenuBar *menuBar = new wxMenuBar();
    menuBar->Append(fileMenu,"&File");
    menuBar->Append(helpMenu,"&Help");

    // ... and attach this menu bar to the frame
    SetMenuBar(menuBar);
#endif // wxUSE_MENUS

#if wxUSE_STATUSBAR
    // create a status bar just for fun (by default with 1 pane only)
    CreateStatusBar(2);
    SetStatusText("Welcome to wxWidgets!");
#endif // wxUSE_STATUSBAR


    // Create a wxGrid object
    wxGrid *grid = new wxGrid(this,300));

    // Then we call CreateGrid to set the dimensions of the grid
    // (8 rows and 10 columns in this example)
    grid->CreateGrid(8,10);

    // We can set the sizes of individual rows and columns
    // in pixels
    grid->SetRowSize(0,60);
    grid->SetColSize(0,120 );

    // And set grid cell contents as strings
    grid->SetCellValue(0,wxT("wxGrid is good"));

    // We can specify that some cells are read-only
    grid->SetCellValue(0,wxT("This is read-only"));
    grid->SetReadOnly(0,3);

    // Colors can be specified for grid cell contents
    grid->SetCellValue(3,wxT("green on grey"));
    grid->SetCellTextColour(3,*wxGREEN);
    grid->SetCellBackgroundColour(3,*wxLIGHT_GREY);

    // We can specify that some cells will store numeric
    // values rather than strings. Here we set grid column 5
    // to hold floating point values displayed with width of 6
    // and precision of 2
    grid->SetColFormatFloat(5,2);
    grid->SetCellValue(0,wxT("3.1415"));

    // Set the grid size to the minimum required to show the content
    grid->Fit();

    // Set the parent frame client size to fit the grid
    this->SetClientSize(grid->GetSize());

}

// event handlers

void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    // true is to force the frame to close
    Close(true);
}

void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
{
    wxMessageBox(wxString::Format
                 (
                    "Welcome to %s!\n"
                    "\n"
                    "This is the minimal wxWidgets sample\n"
                    "running under %s.",wxVERSION_STRING,wxGetosDescription()
                 ),"About wxWidgets minimal sample",wxOK | wxICON_informatION,this);
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)