4
I am currently trying to do the following in QML, simultaneously:
- do dynamic loading of Objects previously created a separate file;
- by doing what is described above, select objects stochastically
For that I am, very basically, using the code below:
import QtQuick 2.0
Item {
id: randomMIDIkeyboardSelector;
property var random: 0;
function randomSelection(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
var out = Math.floor(Math.random() * (max - min + 1)) + min;
console.log(parseFloat(out));
return parseFloat(out);
}
function createMidiKeyboard(itemToBeInstantiated) {
var component = Qt.createComponent("MidiKeyboard.qml");
var midiKeyboard = component.createObject(itemToBeInstantiated, {});
}
function randomPicking() {
random = parseInt(randomSelection(1, 8));
if(random == 1) {createMidiKeyboard(MidiKeyboard);}
if(random == 2) {createMidiKeyboard(MidiKeyboard2);}
if(random == 3) {createMidiKeyboard(MidiKeyboard3);}
if(random == 4) {createMidiKeyboard(MidiKeyboard4);}
if(random == 5) {createMidiKeyboard(MidiKeyboard5);}
if(random == 6) {createMidiKeyboard(MidiKeyboard6);}
if(random == 7) {createMidiKeyboard(MidiKeyboard7);}
if(random == 8) {createMidiKeyboard(Midikeyboard8);}
return random;
}
Component.onCompleted: randomPicking();
}
Basically, I’m creating a random number and using a javascript function to create objects dynamically, that I urge from a if statement
However, when I load the file into the main document, the desired user interface object is not created in the window
To better understand the content of the project I suggest, if you are interested, to consult the link below:
https://github.com/tiagmoraismorgado/TMM_QML_UI_UX_FRAMEWORK_WIP
Luiz Vieira, thank you for Edit.
– tmm88
For nothing Tiago. :) Welcome to SOPT. I withdrew the greetings because this site is not a forum. Unfortunately I don’t use QML, so I don’t really know how to answer your question. But others will know! Good luck!
– Luiz Vieira
by the way, it is the suggestion, for those who want to take a look at the framework working me, follow the link with the video below https://vimeo.com/188973909
– tmm88
James, does this mean that you have solved your difficulty? If yes, do not fail to answer the question yourself, as it can help other people who have the same problem in the future.
– Luiz Vieira
no, Luiz, I haven’t been able to answer the problem yet. thanks for the tip :)
– tmm88
Ah, okay. Meanwhile, take a read in this topic help with what to do if it takes too long to get answers. Good luck.
– Luiz Vieira