How to actually use QWebView::createWindow()



  • i a developing a web browser using qt and c++ and i want to know how to actually use the QWebView::createWindow()
    i am have a class which is the subclass of QWebView the class is webview i always re implement virtual QWebView * QWebView::createWindow(WebPage::WebWindowType type)
    in my new class i know that type is used for getting the window what type of window it is i have understand its use and i have got that this function returns a pointer to a QWebView that has to be displayed but how to get that pointer JavaScript pop-ups are working fine for me but that windows and new tabs i know that there is similar function in QWebPage class which instead returns a pointer to QWebPage but thats not meaningful to me this is more meaningful to me and in the documentation it is given too i have seen the example browser all there is nothing like this.
    i have seen arora source code it helped me a lot but that also does not helped me in this case.
    this was my research and much more i have searched a lot on google and the qt-project forums and many places



  • Ok, yesterday, after scratching my head for two hours, I came up with this quick solution (read "quick", maybe not the best, just a quick solution).

    In your createWindow implementation, inside your QWebView subclass:

    @
    QWebView *WebView::createWindow(QWebPage::WebWindowType type)
    {
    Q_UNUSED(type);

    QWebView *webView = new QWebView;
    QWebPage *newWeb = new QWebPage(webView);
    webView->setAttribute(Qt::WA_DeleteOnClose, true);
    webView->setPage(newWeb);
    webView->show();
    
    return webView;
    

    }
    @

    With this, every time JS wants to open a new window, your app will create and show this new window.

    Hope it helps.

    Regards,
    Javier.



  • thanks man it works can you tell me how it works :)



  • This method is called from the QWebPage itself, searching for a reimplementation on your QWebPage subclass, then, after looking without success, it goes upside to your QWebView reimplementation. Within it, the caller takes control of the object (a new QWebView in this case) and internally inits its QWebPage with the data taken from the web element that shot the event (in this case, the JS script).
    You must take a look at the QtWebKit code at this point (as I should) to fully understand this process.
    I'm glad to help!

    Regards,
    Javier.



  • thanks man i got it you have solved my big problem



  • It works for type browser window pages, but it doesn't seem to work for modal pages, e.g. asking for credentials.



  • Can it open a new window or add window on top of current window without prompting for credentials when everytime javascript wants to open new window.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.