Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can QScriptEngine read a tree of .js files at runtime?
Forum Update on Monday, May 27th 2025

Can QScriptEngine read a tree of .js files at runtime?

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 184 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.
  • K Offline
    K Offline
    kitfox
    wrote on last edited by kitfox
    #1

    I have several .js files that I would like a QScriptEngine to read together. All I can find in the documentation is examples of initializing QScriptEngine by evaluating stings containing JavaScript code. How would JavaScript's import statement work in that case? How would it know where to find the referenced by the import statement?

    For example, how would I go about reading in the following JavaScript files? Could I do it just by specifying I wanted 'birds.js' and 'cats.js' read in and let QScriptEngine find the other files on its own?

    //core.js
    
    function Animal(name) {
        this.name = name;
        this.toString = function() { this.name; }
    }
    
    
    
    //details/animals.js
    import * as Core from '/core.js';
    
    function Bird(name, birdseed) {
        Core.Animal.call(this, name);
        this.birdseed = birdseed;
    }
    Bird.prototype = new Core.Animal();
    
    
    function Cat(name, numLives) {
        Core.Animal.call(this, name);
        this.numLives = numLives;
    }
    Cat.prototype = new Core.Animal();
    
    
    
    //gallery/birds.js
    import {Bird} from '/details/animals.js';
    
    function BigBird(name, birdseed, height) {
        Bird.call(this, name, birdseed);
        this.height = height;
        this.toString = function() { this.name + " " + this.birdseed + " " + this.height; }
    }
    BigBird.prototype = new Bird();
    
    var marthaBird = new BigBird("Martha", 4);
    var fredBird = new BigBird("Fred", 5);
    
    
    
    //gallery/cats.js
    import {Cat} from '/details/animals.js';
    
    function Sabertooth(name, numLives, toothpaste) {
        Cat.call(this, name, numLives);
        this.toothpaste = toothpaste;
    }
    Sabertooth.prototype = new Cat();
    
    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