Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to declare WebEngineScripts and use them in a WebEngineView in Qt6
Forum Updated to NodeBB v4.3 + New Features

How to declare WebEngineScripts and use them in a WebEngineView in Qt6

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 1 Posters 342 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.
  • S Offline
    S Offline
    sevenrats
    wrote on last edited by sevenrats
    #1

    The documentation does not make sufficiently clear how to create WebEngineScripts and WebEngineScriptCollections in Qt6. For example, how would this QML be ported to Qt6, where WebEngineScript is non-creatable.

     WebEngineView
      {
        id: web
        objectName: "web"
        settings.errorPageEnabled: false
        settings.localContentCanAccessRemoteUrls: true
        profile.httpUserAgent: components.system.getUserAgent()
        url: mainWindow.webUrl
        focus: true
        property string currentHoveredUrl: ""
        onLinkHovered: web.currentHoveredUrl = hoveredUrl
        width: mainWindow.width
        height: mainWindow.height
        userScripts: [
         WebEngineScript {
            sourceCode: components.system.getNativeShellScript(),
            injectionPoint: WebEngineScript.DocumentCreation,
            worldId: WebEngineScript.MainWorld
          }
        ]
    
       ... 
    
    S 1 Reply Last reply
    0
    • S sevenrats

      The documentation does not make sufficiently clear how to create WebEngineScripts and WebEngineScriptCollections in Qt6. For example, how would this QML be ported to Qt6, where WebEngineScript is non-creatable.

       WebEngineView
        {
          id: web
          objectName: "web"
          settings.errorPageEnabled: false
          settings.localContentCanAccessRemoteUrls: true
          profile.httpUserAgent: components.system.getUserAgent()
          url: mainWindow.webUrl
          focus: true
          property string currentHoveredUrl: ""
          onLinkHovered: web.currentHoveredUrl = hoveredUrl
          width: mainWindow.width
          height: mainWindow.height
          userScripts: [
           WebEngineScript {
              sourceCode: components.system.getNativeShellScript(),
              injectionPoint: WebEngineScript.DocumentCreation,
              worldId: WebEngineScript.MainWorld
            }
          ]
      
         ... 
      
      S Offline
      S Offline
      sevenrats
      wrote on last edited by
      #2

      The solution to this problem is well documented, my issue was just getting a search engine to show me this document:
      https://doc.qt.io/qt-6/qml-qtwebengine-webenginescriptcollection.html

      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