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. Javascript import does not resolve ApplicationWindow::overlay
Forum Updated to NodeBB v4.3 + New Features

Javascript import does not resolve ApplicationWindow::overlay

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

    I have a problem. When I use Javascript import syntax like this:

    // Misc.js
    .pragma library
    .import QtQuick.Controls 2.2 as QQC2
    
    function dimension( type )
    {
        var overlay = QQC2.ApplicationWindow.overlay;
        return overlay.width / 5;
    }
    
    

    I cannot get QQC2.ApplicationWindow.overlay resolved, in that gets error:

    qrc:/Misc.js:7: TypeError: Cannot read property 'width' of undefined
    qrc:/Misc.js:7: TypeError: Cannot read property 'width' of undefined
    qrc:/Misc.js:7: TypeError: Cannot read property 'width' of undefined
    qrc:/Misc.js:7: TypeError: Cannot read property 'width' of undefined
    qrc:/Misc.js:7: TypeError: Cannot read property 'width' of undefined

    If I put it into QML file:

    width: ApplicationWindow.overlay.width / 5
    

    That's okay. Why does it cause a type error? I am confused. Hope to reply.
    Here is the full source code:

    import QtQuick 2.7
    import QtQuick.Controls 2.0
    import QtQuick.Layouts 1.3
    import "Misc.js" as Misc
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
    
        footer: TabBar {
            id: tabBar
            width: parent.width
            Repeater
            {
                model: ["First", "Second", "Third", "Fourth", "Fifth"]
    
                TabButton
                {
                    text: modelData
                    width: ApplicationWindow.overlay.width / 5
    
                    //width: Misc.dimension( "col-md-3" )
                }
            }
        }
    }
    
    

    我们自己的论坛:http://qtdream.com
    擅长三维角色仿真动画。

    1 Reply Last reply
    0
    • jiancaiyangJ Offline
      jiancaiyangJ Offline
      jiancaiyang
      wrote on last edited by
      #2

      I found ApplicationWindow.overlay is an attached property. Attached property cannot be used directly in JS file.

      我们自己的论坛:http://qtdream.com
      擅长三维角色仿真动画。

      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