Qt QWebView class custom User-Agent

前端 未结 2 2040
小蘑菇
小蘑菇 2020-12-09 21:15

Is there an easy way to setup the User-Agent the QWebView class is using?

The only relevant link I found searching was this

http://www.qtforum.org/article/2

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-09 21:44

    simply,

    class myWebPage : public QWebPage
    {
        virtual QString userAgentForUrl(const QUrl& url) const {
            return "your user agent";
        }
    };
    
    //Attention here is new myWebPage() not new myWebPage(parent) 
    UI->webView->setPage(new myWebPage());
    

提交回复
热议问题