c++ - 使用 wxMac 在 OSX 上构建 wxWidgets wxWebView 失败
问题描述
我正在尝试在 OSX 上使用 wxWebView 构建一个简单的 C++ Web 窗口。我正在使用来自 HomeBrew 的 wxMac 安装。构建未能找到必要的重写类来处理本机 wxWebView。结果是 wxWebView 未定义。
error: unknown type name 'wxWebView'; did you mean 'WebView'?
wxWebView *foo = nullptr;
webview被封装在一个wxDialog消息中,如下:
#ifndef _IRVIZWIN_H_
#define _IRVIZWIN_H_
//-- WX HEADERS
#include <wx/artprov.h>
#include <wx/xrc/xmlres.h>
#include <wx/string.h>
#include <wx/listbox.h>
#include <wx/gdicmn.h>
#include <wx/font.h>
#include <wx/colour.h>
#include <wx/settings.h>
#include <wx/sizer.h>
#include <wx/dirctrl.h>
#include <wx/aui/auibook.h>
#include <wx/stattext.h>
#include <wx/frame.h>
#include <wx/panel.h>
#include <wx/textctrl.h>
#include <wx/choice.h>
#include <wx/statline.h>
#include <wx/button.h>
#include <wx/dialog.h>
#include <wx/checkbox.h>
#include <wx/msgdlg.h>
#include <wx/stc/stc.h>
#include <wx/webview.h>
#include <wx/webviewarchivehandler.h>
#include <wx/webviewfshandler.h>
#include <stdlib.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
class IRVizWin : public wxDialog {
private:
// private data
wxWebView* m_browser; //< browser handler
/// Declares the event table
wxDECLARE_EVENT_TABLE();
// button handlers
/// handles the 'ok' button press
void OnPressOk( wxCommandEvent& ok );
protected:
// window handlers
wxBoxSizer *OuterSizer; ///< outer window sizer
wxBoxSizer *InnerSizer; ///< inner window sizer
wxScrolledWindow *Wnd; ///< main scrolled window
wxStaticLine *FinalStaticLine; ///< final static line
// buttons
wxStdDialogButtonSizer* m_irbuttonsizer; ///< button sizer
wxButton* m_irOK; ///< OK button
public:
IRVizWin(wxWindow* parent,
wxWindowID id = wxID_ANY,
const wxString& title = wxT("IR Visualization"),
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxDEFAULT_DIALOG_STYLE);
~IRVizWin();
};
#endif
#include "IRVizWin.h"
// Event Table
wxBEGIN_EVENT_TABLE(IRVizWin, wxDialog)
EVT_BUTTON(wxID_OK, IRVizWin::OnPressOk)
wxEND_EVENT_TABLE()
IRVizWin::IRVizWin(wxWindow *parent,
wxWindowID id,
const wxString& title,
const wxPoint& pos,
const wxSize& size,
long style)
: wxDialog( parent, id, title, pos, size, style ){
// init the internals
this->SetLayoutAdaptationMode(wxDIALOG_ADAPTATION_MODE_ENABLED);
this->SetSizeHints( wxDefaultSize, wxDefaultSize );
// create the outer sizer
OuterSizer = new wxBoxSizer( wxVERTICAL );
// create the scrolled window
Wnd = new wxScrolledWindow( this,
wxID_ANY,
wxDefaultPosition,
wxDefaultSize,
0,
wxT("scroll"));
// create the inner sizer
InnerSizer = new wxBoxSizer( wxVERTICAL );
// setup the browser window
m_browser = WebView::New(this, wxID_ANY, wxT("http://www.stackoverflow.com/"),
wxDefaultPosition, wxDefaultSize, wxWebViewBackendDefault);
// do something with the browser
// add the final static line
FinalStaticLine = new wxStaticLine( Wnd,
wxID_ANY,
wxDefaultPosition,
wxDefaultSize,
wxLI_HORIZONTAL );
InnerSizer->Add( FinalStaticLine, 1, wxEXPAND | wxALL, 5 );
// setup all the buttons
m_irbuttonsizer = new wxStdDialogButtonSizer();
m_irOK = new wxButton( Wnd, wxID_OK );
m_irbuttonsizer->AddButton( m_irOK );
m_irbuttonsizer->Realize();
InnerSizer->Add( m_irbuttonsizer, 1, wxEXPAND, 5 );
// draw the diag box until we get more info
Wnd->SetScrollbars(20,20,50,50);
Wnd->SetSizer( InnerSizer );
Wnd->SetAutoLayout(true);
Wnd->Layout();
OuterSizer->Add( Wnd, 1, wxEXPAND | wxALL, 5 );
this->SetSizer( OuterSizer );
this->SetAutoLayout(true);
this->Layout();
}
void IRVizWin::OnPressOk( wxCommandEvent& ok ){
this->EndModal( wxID_OK );
}
IRVizWin::~IRVizWin(){
}
这是我的 wxMac 安装版本信息:
wxmac: stable 3.0.5 (bottled), HEAD
Cross-platform C++ GUI toolkit (wxWidgets for macOS)
https://www.wxwidgets.org
/usr/local/Cellar/wxmac/3.0.4_2 (810 files, 22.9MB) *
Poured from bottle on 2020-01-17 at 06:48:37
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/wxmac.rb
从 Homebrew repo 中的 ruby 脚本来看,wxWidgets 似乎是在为 OSX 启用 wxWebView 的情况下构建的。我正在使用以下 CMake 片段来构建它:
set (VizSrcs
IRVizWin.cpp
)
find_package(wxWidgets COMPONENTS net adv aui core gl html propgrid qa ribbon richtext stc xrc base webview REQUIRED)
IF(wxWidgets_FOUND)
INCLUDE("${wxWidgets_USE_FILE}")
include_directories ( . )
message(STATUS " wxWidgets Include: ${wxWidgets_INCLUDE_DIRS}")
include_directories (${wxWidgets_INCLUDE_DIRS})
add_library(VizObjs OBJECT ${VizSrcs})
ELSE(wxWidgets_FOUND)
MESSAGE("wxWidgets not found!")
ENDIF(wxWidgets_FOUND)
HomeBrew下的wxMac是否支持wxWebView?如果是这样,我错过了什么?
解决方案
推荐阅读
- mongodb - MongoDB 5.0 不再允许使用空文档更新现有文档
- excel - 打开带有宏的 Excel 工作簿时,VBA 代码死机
- python - 如何使用 Python 登录 goole 帐户并发送 POST 请求?
- sql - 如何从多表创建投影
- html - 在表格中添加新行时如何使每列为空
- java - 使用 Thread.join 的服务启动时间
- python - Python Tornado WebSocket:不在第二个网络接口上工作
- docker - docker-compose 突然出现 I/O 错误
- git - 为 git difftool 标签(目录名称)“左”和“右”配置不同的名称?
- python - 在 Python 中使用 Samba 客户端将文件从 Linux 复制到 Windows