BlinCTDec. 30, 2018, 8:22 a.m.
Динамическое создание обьекта и добавление в StackView QML
Всем привет.
Столкнулся с такой проблемой, на стороне С++ я создаю динамически обьект, его получаю на стороне QML и нужно его добавить в StackView.
И как это сделать не могу придумать. Ниже кидаю крестовую часть и QML
TimerContainer::TimerContainer(QObject *parent) : QObject(parent) { vec_ = new vector<CircleTimer*>(); createTimer(); } CircleTimer *TimerContainer::getTimer(int index) { return vec_->at(index); } void TimerContainer::delTimer(int index) { vec_->erase(vec_->begin() + index); emit sizeChanged(vec_->size()); } void TimerContainer::createTimer() { auto timer = new CircleTimer(); vec_->push_back(timer); emit sizeChanged(vec_->size()); emit addNewTimer(timer); } void TimerContainer::createTimers(int number) { if (number != 0) { while (number != 0) { createTimer(); --number; } } } int TimerContainer::size() { return vec_->size(); }
QML
StackView { id: timers property var currentTimer: QtObject property int currentIndex: -1 property int targetId: 0 function selectTimer(idx) { for (var i = 0; i < timerContainer.size; ++i) { //timerContainer.getTimer(idx).visible = (i === idx); //console.log("idx: " + i + " - " + timerContainer.getTimer(idx).visible) } currentTimer = timerContainer.getTimer(idx); currentIndex = idx; } //function addTimer(timer) { // timer.parent = circletimercontent1; // timer.anchors.fill = circletimercontent1; //} Component.onCompleted: { for (var i = 0; i < timerContainer.size; ++i) { timers.push(timerContainer.getTimer(i)); } timers.selectTimer(0); timerContainer.addNewTimer.connect(timers.addTimer); } Connections { target: currentTimer } }
Наткнулся где то на форумах на
var newComponent = Qt.createComponent(arg)
var newObj = newComponent.createObject(arg)
но не уверен может ли это мне помочь.
Буду признателен если тот кто с чем то подобным сталкивался поможет разобратся в этом.
We recommend hosting TIMEWEB
Stable hosting, on which the social network EVILEG is located. For projects on Django we recommend VDS hosting.Do you like it? Share on social networks!
B
- Bogdannn
- March 28, 2024, 5:15 a.m.
C++ - Test 001. The first program and data types
- Result:46points,
- Rating points-6
Last comments
Qt Linux - Lesson 001. Autorun Qt application under Linux как сделать автозапуск для флэтпака, который не даёт создавать файлы в ~/.config - вот это вопрос ))
АК
Qt WinAPI - Lesson 007. Working with ICMP Ping in Qt Без строки #include <QRegularExpressionValidator> в заголовочном файле не работает валидатор.
Анатолий КононенкоFeb. 5, 2024, 12:50 p.m.
EVADec. 25, 2023, 9:30 p.m.
Boost - static linking in CMake project under Windows Сделал всё по-как у вас, но выдаёт ошибку [build] LINK : fatal error LNK1104: не удается открыть файл "libboost_locale-vc142-mt-gd-x64-1_74.lib" Хоть убей, не могу понять в чём дел…
Qt/C++ - Lesson 056. Connecting the Boost library in Qt for MinGW and MSVC compilers Для решения твой проблемы добавь в файл .pro строчку "LIBS += -lws2_32" она решит проблему , лично мне помогло.
Now discuss on the forum
Как получить в массив значения из связанной модели? Спасибо, разобрался:))
AC
QML Обнулить значения SpinBox Доброго времени суток, не могу разобраться с обнулением значение SpinBox находящего в делегате. import QtQuickimport QtQuick.ControlsWindow { width: 640 height: 480 visible: tr…
Alexandru CodreanuJan. 19, 2024, 10:57 p.m.
BlinCTDec. 27, 2023, 7:57 p.m.
ДмитрийJan. 10, 2024, 3:18 p.m.
Evgenii LegotckoiDec. 12, 2023, 5:48 p.m.
;-)
Да, ошибочка на внимательность)