View Full Version : webview custom error pages

21st March 2011, 15:46
hi sorry for posting alot, its just that i want to write a real chrome alternative browser, now i need to know how to create custom error pages for the browser, for example when the address is not found, when there is no network connection... i don't know what to do

21st March 2011, 20:10
Have a look at QWebPage::extension().

21st March 2011, 21:23
thanks alot!

Added after 56 minutes:

please sorry, i looked at it, but iam very confused, i don't know how to reimplement that methot, this is what i wanted to try

bool QWebPage::extension ( QWebPage::ErrorPageExtension, const ExtensionOption * option = 0, ExtensionReturn * output = 0 ) , but what else! i know how to reimplement virtual methods, but this one is verry different, iam very confused, and the demo browser don't use it at all, so i don't know where to find and example using it, please help!!!

21st March 2011, 22:42
How is it different from other virtual methods?

21st March 2011, 23:32
for the other method, for example the contexMenuEvent, i just had to create the menu i wanted and add actions into it, but now i need custom error pages, and here i have seen nowhere someting very precise, i know QWebPage::extension() is the right method to use, but iam lost, i don't know where to start, please it is not tha i want you to solve the problem for me, normaly that your hint should be enough, but please help me, i spent all the day on this!

also sorry for the quality of my english, my mother tongue is french!


21st March 2011, 23:51
Look at the parameters you receive in the method. Cast them to a proper type based on the extension you are currently handling and fill in the return parameter based on the option parameter.

22nd March 2011, 11:58
but the return parametter is just a boolean, how about the custom webpage i want to load in case of network error for example?

22nd March 2011, 12:11
I'm not speaking about return value but one of the input arguments that has the type "ExtensionReturn". The other has a type of "ExtensionOption" thus my "return" and "option" names.

22nd March 2011, 14:17
i will look at it again, and i will report here, but to be honnest, iam very lost i don't know if i should be ashamed for that, it is very abstract, i still don't know where to start and what to write, anyway thanks very much for your help, and your precious time!

22nd March 2011, 14:28
I will not do your work for you and I will not teach you general programming here. You should already be familiar with programming before you start doing any complex projects with Qt. Start by looking at the documentation of structures you get, the fields they have and what they should contain. Then fill those structures with data depending on the effect you want to achieve.

23rd March 2011, 01:13
bool webPage::extension ( Extension extension, const ExtensionOption * option, ExtensionReturn * output ){

const QWebPage::ErrorPageExtensionOption* info = static_cast<const QWebPage::ErrorPageExtensionOption*>(option);
QWebPage::ErrorPageExtensionReturn* errorPage = static_cast<QWebPage::ErrorPageExtensionReturn*>(output);
errorPage->content = QString("<html><head><title>Failed loading page</title></head><body>%1</body></html>").arg(info->errorString).toUtf8();
return true;


Added after 28 minutes:

now it works perfect, thanks very much!!! the problem is solved

23rd March 2011, 08:26
You should check the type of extension being handled before casting and using the parameters.

23rd March 2011, 09:49
ok, thanks!