Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. TypeError: Property 'sizedHeight' of object [object Object] is not a function

TypeError: Property 'sizedHeight' of object [object Object] is not a function

Scheduled Pinned Locked Moved Solved Qt 6
2 Posts 1 Posters 671 Views 1 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.
  • R Offline
    R Offline
    Rich v
    wrote on last edited by Rich v
    #1

    I have some code that has worked in Qt5 but is giving me trouble in Qt6 and I haven't figured it out. I'm a bit stumped - any suggestions are appreciated.

    I get the below runtime error:

    qrc:/myappuri/main.qml:53:9: TypeError: Property 'sizedHeight' of object [object Object] is not a function
    

    I have a basic main.qml that imports a qml module:

    // main.qml
    import QtQuick 2.15
    import QtQuick.Controls 2.15
    import QtQuick.Window 2.15
    import QtQuick.Layouts 1.12
    import mylib1 1.0
    
    Window
    {
        width: 1024
        height: 600
        x: 0
        y: 0
        color: "darkgray"
        visible: true
    
        MyType1
        {
            width: 600
    //        height: 200
            height: Qt.binding(BCSize.sizedHeight(100, 200))
            color: "purple"
            y: 200
        }
    }
    

    The module contains the BCSize singleton that has some sizing functions:

    // BCSize.qml
    pragma Singleton
    import QtQuick 2.0
    import QtQuick.Window 2.2
    import QtQml 2.2
    
    QtObject
    {
    
        // nominal sizes that the screens were designed to.
        readonly property int largeScreenDesignWidth: 1024
        readonly property int largeScreenDesignHeight: 600
        readonly property int smallScreenDesignWidth:  320
        readonly property int smallScreenDesignHeight: 240
    
        // Our initial and current screen size
        // On the desktop, we'll mimic the Littlefoot/Jupiter display
        // You can mimic different screen sizes by re-setting these in code
        // which is a good way to test resolution independence
    
        // note that this crashes on the printer if you go less than about 870 x 520 - looks like a Qt bug
        property int screenWidth:  1024
        property int screenHeight: 600
    
        property bool isSmallScreenSize: screenWidth <= smallScreenDesignWidth
    
        // general-purpose size calculator. You can use it but it is probably easier to use the ones below
        function sizedValue( designedMin, designedMax, screenSize, screenMin, screenMax )
        {
            // We want to calculate "size" given the current screenSize
            // This formula shows equal ratios between the designed object sizes and the design screen sizes
            //     (size - designedMin) / (designedMax - designedMin) = (screenSize - screenMin) / (screenMax - screenMin)
            //
            // A little algebra solving for size and we get this formula:
            var size = designedMin + ((screenSize - screenMin) * (designedMax - designedMin) / (screenMax - screenMin));
    
            // don't allow negative sizes
            return Math.max( 0, size );
        }
    
    
        // returns an item's height given its size for the large screen and the size for the small screen
        // can also be used for vertical positions
        function sizedHeight( designedSmall, designedLarge )
        {
            return sizedValue( designedSmall, designedLarge, screenHeight, smallScreenDesignHeight, largeScreenDesignHeight );
        }
    
        // returns an item's width given its size for the large screen and the size for the small screen
        // can also be used for horizontal positions
        function sizedWidth( designedSmall, designedLarge )
        {
            return sizedValue( designedSmall, designedLarge, screenWidth, smallScreenDesignWidth, largeScreenDesignWidth );
        }
    
        // use this function if you want 'expand' animation (from smalldimension to actual dimension)
        // returns appropriate height for the 'current height'
        // at the end of the animation, this function eventually returns same as 'sizedHeight'
        function sizedHeightAnimate( designedSmall, designedLarge, currentHeight )
        {
            return sizedValue( designedSmall, designedLarge, currentHeight, smallScreenDesignHeight, largeScreenDesignHeight );
        }
    
        // use this function if you want 'expand' animation (from smalldimension to actual dimension)
        // returns appropriate width for the 'current width'
        // at the end of the animation, this function eventually returns same as 'sizedWidth'
        function sizedWidthAnimate( designedSmall, designedLarge, currentWidth )
        {
            return sizedValue( designedSmall, designedLarge, currentWidth, smallScreenDesignWidth, largeScreenDesignWidth );
        }
    
        // returns an item's count (any property which is not width or height) given its count for the large screen
        // and the count for the small screen
        function sizedCount( designedSmall, designedLarge )
        {
            return sizedValue( designedSmall, designedLarge, screenWidth, smallScreenDesignWidth, largeScreenDesignWidth );
        }
    
        // returns an item's height given its size for the large screen scaled linearly to the small screen
        function scaledHeight( designedLarge )
        {
            var result = designedLarge * screenHeight / largeScreenDesignHeight;
            return result;
        }
    
        // returns an item's width given its size for the large screen scaled linearly to the small screen
        function scaledWidth( designedLarge )
        {
            var result = designedLarge * screenWidth / largeScreenDesignWidth;
            return result;
        }
    }
    
    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rich v
      wrote on last edited by
      #2

      Figured out that I didn't have 'singleton' assigned to the BCSize.qml file in the qmldir, which is now auto-generated. I had to add:

      set_source_files_properties(BCSize.qml
      PROPERTIES
      QT_QML_SINGLETON_TYPE TRUE
      )

      1 Reply Last reply
      2

      • Login

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