Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Qt 5.6 custom user agent not working

Qt 5.6 custom user agent not working

Scheduled Pinned Locked Moved Solved QtWebEngine
3 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    ThatDud3
    wrote on last edited by
    #1

    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();
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        ThatDud3
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved