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. Crash when trying to bind Window.height to WebEngineView.contentsSize.height (short code)
Qt 6.11 is out! See what's new in the release blog

Crash when trying to bind Window.height to WebEngineView.contentsSize.height (short code)

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
3 Posts 3 Posters 1.0k Views 2 Watching
  • 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.
  • A Offline
    A Offline
    alwayslearning
    wrote on last edited by alwayslearning
    #1

    Hi,

    I use Qt 5.10.1 on up-to-date Windows 10 and the following simple program does not show any window:

    import QtQuick 2.10
    import QtQuick.Window 2.10
    import QtWebEngine 1.5
    
    Window { id: w
        visible: true
        title: "Test"
    
        // with this line, the program crashes before showing anything:
        height: v.contentsSize.height
    
        WebEngineView { id: v
            anchors.left: w.left
            anchors.right: w.right
            anchors.top: w.top
    
            onContentsSizeChanged: {
                console.log(contentsSize) // no output if not both width and height properties of the web view are specified
                w.height = contentsSize.height
            }
    
            // if any of the following 2 lines are omitted, the web view the ":-)" string in the web view does not show up and the window looks empty although anchors.left and anchors.right are set above and the height is set
            // width: 100
            // height: 100
    
            // The following line crashes the program before showing the window
            // height: v.contentsSize.height
    
            Component.onCompleted: {
                loadHtml(":-)");
            }
        }
    }
    

    I specifically want the window to be as high as the web view when its size is not constrained. Relevant documentation link: http://doc.qt.io/qt-5/qml-qtwebengine-webengineview.html#contentsSize-prop.

    Thanks!

    DiracsbracketD 1 Reply Last reply
    0
    • A alwayslearning

      Hi,

      I use Qt 5.10.1 on up-to-date Windows 10 and the following simple program does not show any window:

      import QtQuick 2.10
      import QtQuick.Window 2.10
      import QtWebEngine 1.5
      
      Window { id: w
          visible: true
          title: "Test"
      
          // with this line, the program crashes before showing anything:
          height: v.contentsSize.height
      
          WebEngineView { id: v
              anchors.left: w.left
              anchors.right: w.right
              anchors.top: w.top
      
              onContentsSizeChanged: {
                  console.log(contentsSize) // no output if not both width and height properties of the web view are specified
                  w.height = contentsSize.height
              }
      
              // if any of the following 2 lines are omitted, the web view the ":-)" string in the web view does not show up and the window looks empty although anchors.left and anchors.right are set above and the height is set
              // width: 100
              // height: 100
      
              // The following line crashes the program before showing the window
              // height: v.contentsSize.height
      
              Component.onCompleted: {
                  loadHtml(":-)");
              }
          }
      }
      

      I specifically want the window to be as high as the web view when its size is not constrained. Relevant documentation link: http://doc.qt.io/qt-5/qml-qtwebengine-webengineview.html#contentsSize-prop.

      Thanks!

      DiracsbracketD Offline
      DiracsbracketD Offline
      Diracsbracket
      wrote on last edited by
      #2

      @alwayslearning
      This seems to be related with a bug when accessing contentsSize too early:
      https://bugreports.qt.io/browse/QTBUG-65942

      Apparently, this still doesn't work correctly in Qt 5.10.0, although the bug was considered solved?

      As a check, I tried accessing the property in the onLoadProgressChanged handler:

              onLoadProgressChanged: {
                  if (loadProgress===100)
                      console.debug(contentsSize.height)
              }
      

      This works (I tried by setting the url property to a webpage). Maybe as a workaround, you could set your window height in that handler.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        The bug report states that 5.10.0 is also affected. It's been solved for 5.9.5 so it will likely be also for the release of 5.11.

        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

        • Login

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