Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
How to use my own javascript function in QML?

I'm trying to call my own function to add an image source. The code is similar to this:

    function pics()
    {
        var source = "file:/home/nabil/Downloads/4.png"
        if (ident === "Nabil") {
            source = "qrc:images/Plane1.png" ;
        }
        return source;
    }

    Image
    {
        id: myIDImage
        source: myIDImage.pics() //here I am calling my function
        x: 0
        y: 0
        width: 30
        height: 30
    }

Can anyone please tell me the way of calling my own function?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You would do something like this:

import QtQuick 2.12

Item {
    function fibonacci(n){
        var arr = [0, 1];
        for (var i = 2; i < n + 1; i++)
            arr.push(arr[i - 2] + arr[i -1]);

        return arr;
    }
    TapHandler {
        onTapped: console.log(fibonacci(10))
    }
}

So, you do not need to call pics on myIDImage.

source: pics()

Moreover, in your case, you could just do something like:

source: (ident === "Nabil") ? "qrc:images/Plane1.png" : ""
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!