Answer the question
In order to leave comments, you need to log in
How to create object from .js file in QML?
What am I doing wrong?
There is a js file, a primitive constructor function.
in qml I want to create an object from this js file by allocating memory and fill it.
function device( ip,name,port,community,oid_count)
{
this._ip=ip;
this._name=name;
this._port=port;
this._community=community;
this._oid_count=oid_count;
}
import QtQuick 2.7
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.0
import "device_obj.js" as Device
ApplicationWindow {
visible: true
width: 640
height: 480
color: "#a3a3a3"
title: qsTr("Hello World")
Button {
id: button_ok
x: 468
y: 423
text: qsTr("Button_OK")
onClicked:
{
var ip="123";
var name="123";
var port="123";
var community="123";
var oid_count="123"
var device= new Device(ip,name,port,community,oid_count);
}
}
}
Answer the question
In order to leave comments, you need to log in
There is a special, street js.
We create the Device.qml file, inside it we write:
Item {
property string ip
property string port
...
// Тут может быть и функция-конструктор
}
Device {
id: device
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question