Qt World Summit: Register Today!

Qt 5.6 custom user agent not working

  • How to change user agent using custom QWebEngineProfile
    I tried to subclass QWebEngineProfile but it is not working

        QApplication a(argc, argv);
        CustomWebEngineProfile profile;
        QWebEngineView view;
        QWebEnginePage page((QWebEngineProfile*)&profile);
        QVBoxLayout layout;
        Widget w;
        QTimer::singleShot(7000, &a, SLOT(quit()));
        qDebug() << "httpUserAgent: " << view.page()->profile()->httpUserAgent();
        // still prints the default user-agent with ...QtWebEngine/5.6.0
        // httpUserAgent:  "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.6.0 Chrome/45.0.2454.101 Safari/537.36"
        return a.exec();

  • Lifetime Qt Champion


    Out of curiosity who did you subclass QWebEngineProfile since its interface doesn't have any virtual method (not counting the inherited methods) ?

    I haven't used that class yet but from the documentation setHttpUserAgent looks like what you might be looking for.

    Hope it helps

  • Yes I figured it out... The problem is a lot of new documentation (esp. 5.6) doesn't provide even the most simple usage examples even for such a simple thing as changing the user-agent.
    Marking as solved.

Log in to reply