Search code examples
qtqwebviewqtwebengine

Change user agent in QWebEngineView


How to change the user agent in QWebEngineView? I know that for QWebView there is a way to do this but I didn't find the solution for the QWebEngineView.


Solution

  • While constructing QWebEnginePage as one of the arguments you may specify QWebEngineProfile.

    QWebEngineProfile - it is a class which contains different settings for your profile which can be shared between web pages.

    For setting user agent you will need to use:

    void QWebEngineProfile::setHttpUserAgent(const QString & userAgent)
    

    http://doc.qt.io/qt-5/qwebengineprofile.html#setHttpUserAgent

    QWebEngineProfile is available since Qt 5.5.