Short question:
How to make different instances of webkit in C++?
Long question:
I'm writing a simple webbrowser with Webkit2 in C++ on ubuntu with a gtkmm gui. I would like to use different pages with different Webkit instances.
So far, I have a window to which I can add and remove pages/tabs and Webkit successfully running in the first page/tab. When I add a second page/tab with an other instance of Webkit I'm not able to load any webpage. My code in the callback function to add a page/tab:
m_WebKit00 = WEBKIT_WEB_VIEW(webkit_web_view_new()); // WebKitWebView* was initialized to the nullptr in the constructor
surf00 = Glib::wrap(GTK_WIDGET(m_WebKit00)); // Gtk::Widget* was initialized to the nullptr in the constructor
m_pViewport00->add(*surf00); // Gtk::Viewport* was initialized to the nullptr in the constructor
m_pNotebook->append_page(*m_pViewport00, *m_pTab00); // Gtk::Notebook* was initialized to the nullptr in the constructor
// same for m_WebKit01, surf01 and so on, ex:
m_WebKit01 = WEBKIT_WEB_VIEW(webkit_web_view_new());
// at start of program one page/tab is created and it is selected; adding/removing pages/tabs works perfectly
Code in the on_notebook_switch_page() callback which is run if an other page/tab is selected by the user after adding a page:
// here I have a switch to check which page/tab is selected.
// WebKitWebView** m_WebKit(nullptr) // initialized by the constructor
m_WebKit = &m_WebKit00; // if page 0 is selected // WebKitWebView** was initialized to the nullptr in the constructor
m_WebKit = &m_WebKit01; // if page 1 is selected
// and so on;
The idea is to let m_WebKit point to the webkit instance of the selected page/tab.
Now I want to load the webpage when someone enters an url in the searchentry with:
webkit_web_view_load_uri(m_WebKit, &url[0]);
// reuse this function whenever the searchentry is used, no matter on what page/tab you are
This works perfectly for page 0, but not for page 1. On page 1 nothing loads, no errors or changes to the page or viewport.
What am I missing here? Isn't it possible to use multiple instances of webkit? Would a solution be the use of smart/shared/weak pointers or is the no loading caused by something else? Any better techniques and/or webkit tutorials?
Please help!! Thank you
- @273K: edited the code with the same result