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. Qt4.8 assigning a JavaScript function to a property
Forum Updated to NodeBB v4.3 + New Features

Qt4.8 assigning a JavaScript function to a property

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

    I want to pass a JavaScript function to a component through a property. It looks like this is possible in Qt 5.2 with the var type. Is there any solution for Qt 4.8?

    1 Reply Last reply
    0
    • U Offline
      U Offline
      uroller
      wrote on last edited by
      #2

      I thought this was interesting. While you can't assign a function apparently, you can declare a function when use a component. So below, thing1 will use the somefunc declared in the Thing component. thing2 will use the custom somefunc declared when we declare thing2. Still can't find a better way.

      main.qml:
      @
      import QtQuick 1.0

      Item
      {
      Thing
      {
      id: thing1
      }

      Thing
      {
          id: thing2;
      
          function somefunc()
          {
              console.log("custom func")
          }
      }
      

      }
      @

      Thing.qml:
      @
      import QtQuick 1.0

      Item
      {
      function somefunc()
      {
      console.log("default")
      }

      Component.onCompleted:
      {
          somefunc();
      }
      

      }
      @

      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