Qt 5.6 custom user agent not working
Solved
QtWebEngine
-
How to change user agent using custom QWebEngineProfile
I tried to subclass QWebEngineProfile but it is not workingQApplication a(argc, argv); CustomWebEngineProfile profile; QWebEngineView view; QWebEnginePage page((QWebEngineProfile*)&profile); view.setPage(&page); QVBoxLayout layout; layout.addWidget(&view); Widget w; w.setLayout(&layout); w.show(); 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" view.load(QUrl("http://whatsmyuseragent.com/")); return a.exec();
-
Hi,
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