PDA

View Full Version : segmentation fault in qwebkit::url



wambagilles
3rd April 2011, 12:06
when i use my web browser, it sometime crashes and i don't know why, this is what i get with gdb

SIGSEGV segmentation fault received at QWebkit::url, please help

ChrisW67
3rd April 2011, 23:41
Start by helping yourself... if you provide no information then at best you will get an answer based on no information.

There's no class called QWebKit in my Qt installs so I assume you mean QWebView. Have you set a url with QWebView::setUrl() and does that QUrl object still exist?

wambagilles
4th April 2011, 08:14
the only setUrl() statement i have is this webView->setUrl(QUrl("about:blank")); , i instead use constant requests with constant QUrl, i wil also try using pointers, and i will try to locate the section of the code from where the error is!
thanks

wambagilles
4th April 2011, 22:56
hi, i isolated the error, this is the code line that crashes the browser

QPushButton *notLoading = new QPushButton(this);
notLoading -> setIcon(QIcon(QWebSettings::iconForUrl(QUrl(webVie w->url()))));

everything seems fine, i don't know what is wrong, please help!

SixDegrees
4th April 2011, 23:08
There's too much going on in the call to setIcon - there are four additional function calls in there. Seperate them so each one's output can be examined.

I would guess that iconForURL is returning null. There's no guarantee that a website will have an icon associated with it, but you're assuming this always returns a valid value.

It may also be that the url returned by the innermost call is invalid. You don't check that, either.

That's just speculation, however. Break the problem down and examine the individual parts.

wambagilles
4th April 2011, 23:36
sorry in fact this is the faulty line
notLoading -> setIcon(QIcon(QWebSettings::iconForUrl(QUrl(widget ( index ) ->findChild<QWebView *>()->url()))));

i changed it with the one from previous post, this one:

WebView *webView = qobject_cast<WebView*>(sender());
QPushButton *notLoading = new QPushButton(this)
notLoading -> setIcon(QIcon(QWebSettings::iconForUrl(QUrl(webVie w->url()))));

and now things seems better, i am now happy though i don't know what was going wrong with the previous code!

thanks alot for your help,thanks for sharing your knoledge, i hope i will also become a Qt expert! thanks!

SixDegrees
4th April 2011, 23:41
Nesting your calls like that is bad practice, and makes the code difficult to debug. Break those single lines into multiple calls producing intermediate results that can be examined when trouble arises. The compiler is creating intermediate variables to hold all those values anyway; there is no advantage to not doing the same explicitly.