无法在CentOS中构建wxWidget项目,错误:类型为'wxAppConsole *'的static_cast无效

时间:2014-01-09 04:41:59

标签: c++ c wxwidgets

我正在尝试构建wxWidget GUI应用程序,我的应用程序使用wxApp类和相关库。当我构建项目时,我得到了错误控制台。

09:58:20 **** Incremental Build of configuration Debug for project wxW-gettingStart ****
make all 
Building file: ../BatScannerApp.cpp
Invoking: GCC C++ Compiler
g++ -I/opt/motorola-scanner/include -O0 -g3 -Wall -c -fmessage-length=0  `wx-config --cxxflags` -MMD -MP -MF"BatScannerApp.d" -MT"BatScannerApp.d" -o "BatScannerApp.o" "../BatScannerApp.cpp"
../BatScannerApp.cpp: In function ‘BatScannerApp& wxGetApp()’:
../BatScannerApp.cpp:13: error: invalid static_cast from type ‘wxAppConsole*’ to type ‘BatScannerApp*’
../BatScannerApp.cpp: In function ‘wxAppConsole* wxCreateApp()’:
../BatScannerApp.cpp:13: error: cannot convert ‘BatScannerApp*’ to ‘wxAppConsole*’ in return
make: *** [BatScannerApp.o] Error 1

09:58:21 Build Finished (took 1s.378ms)

根据错误,调用{IMPLEMENT_APP}时出现了转换问题 我的源代码包含2个用于使用wxApp和wsFrame类的类。

#ifndef BATSCANNERAPP_H_
#define BATSCANNERAPP_H_

#include <wx/wx.h>

class BatScannerApp {
public:
    BatScannerApp();
    virtual ~BatScannerApp();

    virtual bool onInit();
};

#endif /* BATSCANNERAPP_H_ */

IMPLEMENT_APP(BatScannerApp)
//wxIMPLEMENT_APP_CONSOLE(BatScannerApp)

BatScannerApp::BatScannerApp() {
    // TODO Auto-generated constructor stub

}

BatScannerApp::~BatScannerApp() {
    // TODO Auto-generated destructor stub
}

bool BatScannerApp::onInit()
{
    BatScannerFrame *mainFrame = new BatScannerFrame(wxT("Minimal wxWidgets App"));
    mainFrame -> Show(true);

    return true;
}

#ifndef BATSCANNERFRAME_H_
#define BATSCANNERFRAME_H_

#include <wx/wx.h>

class BatScannerFrame : public wxFrame {
public:
    //  constructors
    BatScannerFrame();
    BatScannerFrame(const wxString& title);
    virtual ~BatScannerFrame();

    //event handlers
    void onQuit(wxCommandEvent& event);
    void onAbout(wxCommandEvent& event);

private:
    //  Handle the events
    DECLARE_EVENT_TABLE()
};

#endif /* BATSCANNERFRAME_H_ */

#include "BatScannerFrame.h"

// Event table for BatScannerFrame
BEGIN_EVENT_TABLE(BatScannerFrame, wxFrame)
    EVT_MENU(wxID_ABOUT, BatScannerFrame::onAbout)
    EVT_MENU(wxID_QUIT, BatScannerFrame::onQuit)
END_EVENT_TABLE()


BatScannerFrame::BatScannerFrame() {
    // TODO Auto-generated constructor stub

}

BatScannerFrame::BatScannerFrame(const wxString& title)
                :wxFrame(NULL, wxID_ANY, title)
{
    // TODO Set the frame Icon

    // Create a menu bar
    wxMenu *fileMenu = new wxMenu;
    wxMenu *helpMenu = new wxMenu;

    // About item should be under help menu
    helpMenu -> Append(wxID_ABOUT, wxT("&About \tF1"),
                wxT("Show about dialog..."));
    fileMenu -> Append(wxID_EXIT, wxT("E&xit\tAlt-X"),
                wxT("Quit this program"));

    wxMenuBar *menuBar = new wxMenuBar();
    menuBar -> Append(fileMenu, wxT("&File"));
    menuBar -> Append(helpMenu, wxT("&Help"));

    // Attache this menu to the frame
    SetMenuBar(menuBar);

    // Create Status bar
    CreateStatusBar(2);
    SetStatusText(wxT("Welcome to wxWidget..."));

}

BatScannerFrame::~BatScannerFrame() {
    // TODO Auto-generated destructor stub
}

void BatScannerFrame::onQuit(wxCommandEvent& event)
{
    //  Close the frame
    close(true);
}

void BatScannerFrame::onAbout(wxCommandEvent& event)
{
    //  About the application
    wxString msg;
    msg.Printf(wxT("Hello and welcome to %s"), wxVERSION_STRING);
    wxMessageBox(msg, wxT("About minimal."), wxOK | wxICON_INFORMATION,
            this);
}

我是C / C ++中GUI的新手,请帮助我在使用wxWidget库时解决这个转换问题。

1 个答案:

答案 0 :(得分:1)

BatScannerApp应该继承wxAppwxAppConsole