QWebEngine DemoBrowser retrieve cookies and current URL



  • Hi, I'm using the QWebEngine DemoBrowser in my application. As this is really a full fledged browser, so i'm not sure about how to actually retrieve the cookies for a specific page.

    Normally using a single QWebEngineView i would do the following to retrieve the cookies

    QWebEngineCookieStore *browser_cookie_store = ui->browser->page()->profile()->cookieStore();
    connect( browser_cookie_store, &QWebEngineCookieStore::cookieAdded, this, &Terminal::handleCookieAdded );
    
    

    And the slot would be written as such

    void Terminal::handleCookieAdded(const QNetworkCookie &cookie)
    {
      cookie_jar->insertCookie( cookie );
      //qDebug() << cookie.toRawForm() << "\n\n\n";
    }
    

    And to check the current URL i would normally do this

    /* Connect the urlChanged signal */
     connect( ui->browser, &QWebEngineView::urlChanged, this, &Terminal::checkCurrentURL );
    
    /* checkCurrentURL SLOT */
    void Terminal::checkCurrentURL(const QUrl &url)
    {
      if ( url.url() == "https://www.certainwebsite.com" ) {
        qDebug() << "Logged into " << url.toDisplayString();
        emit loggedIntoTerminal();
      }
    }
    

    But how to actually achieve this using the DemoBrowser provided with Qt WebEngine example.



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