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);
        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();
    
    

  • Lifetime Qt Champion

    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



  • 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
 

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