Strumenti Utente

Strumenti Sito


programmazione:cpp:crowcpp_wxwebview

Usare Crowcpp con una wxWebview

Autore: Fabio Di Matteo
Ultima revisione: 30/10/2025 09:03

Un esempio minimo di come usare una wxWebview con CrowCpp.

main.cc

#include <wx/wxprec.h>
#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif
#include "wx/xrc/xmlres.h"
#include <wx/webview.h>
 
#include "crow.h" 
 
class crowThread : public wxThread
{
   public:
	crowThread();
 
   private:
	virtual void *Entry();
};
 
crowThread::crowThread(): wxThread(wxTHREAD_DETACHED) 
{
 
}
 
void *crowThread::Entry () 
{
    crow::SimpleApp app;          
 
    CROW_ROUTE(app, "/hello")     
    ([](){
        return "<h1>Hello, world</h1><p>Un esempio minimo di uso di crow in combinazine con wxWebview</p>";
    });
 
    app.port(18080).multithreaded().run(); 
    return nullptr;
}
 
 
 
 
class webApp : public wxApp {
public:
    virtual bool OnInit() {
        wxBoxSizer* sizer;
        wxFrame* frame = new wxFrame(nullptr, wxID_ANY, "Minimal wxWebView", wxDefaultPosition, {1024,768});
        sizer = new wxBoxSizer(wxVERTICAL);
        wxWebView* webview = wxWebView::New(frame, wxID_ANY);
        sizer->Add(webview, 1, wxEXPAND);
        frame->SetSizer(sizer);
        frame->Show();
 
 
        crowThread* t = new crowThread();
        if (t->Run() != wxTHREAD_NO_ERROR) {
            delete t;
            wxLogError("Impossibile avviare il thread");
        }
        sleep(1);
        webview->LoadURL("http://localhost:18080/hello");
        return true;
    }
};
 
wxIMPLEMENT_APP(webApp);

makefile

CPP = g++ 
OPTS =  `wx-config --cxxflags --libs std,webview`
INCLUDE= -I.
 
all:
	$(CPP) $(INCLUDE) main.cc -o wxtest $(OPTS)

Si presuppone avere crow.h e la cartella crow allo stesso livello di main.cc .

meson.build

se si vuole compilare con meson e ninja ecco la configurazione:

meson.build

project('wxtest', 'cpp')
 
incdir = include_directories('.')
extra_args= []
wxwidgets = dependency('wxwidgets', version : '>=3.0.0', modules : ['std', 'stc','webview'])
 
#meson.add_install_script('install.sh')
 
executable('wxtest','main.cc', 
			dependencies :[wxwidgets],
			c_args : extra_args,
            include_directories : incdir, 
			install : false, 
			install_dir : '/usr/local/bin')
programmazione/cpp/crowcpp_wxwebview.txt · Ultima modifica: 30/10/2025 09:23 da Fabio Di Matteo