I’m working on a QUL / Qt Quick Ultralite application (targeting ESP32, using QUL 2.9.0) where I have:
A CharacterSelectors.qml component that uses a Repeater to render multiple character-selector subcomponents.
A TextEditVM (C++ / QUL view-model) with getWord() method, which is supposed to concatenate the currently selected characters from each CharacterSelector. and a setter setChar(int index, const std::string& data)
From the logs (via idf.py monitor), I see that when I select individual characters, those delegate components are created and some logging occurs. However, when I call getWord() from the VM, the returned word is incomplete (often empty).
Below are simplified / trimmed but representative versions of my .qml and C++ VM code. I hope someone can spot what I’m doing wrong or suggest a better pattern.
CharacterSelectors.qml
import QtQuick 2.15
import QtQuick.Controls 2.15
import Constants 1.0
import "../BaseControl"
Row {
id: root
spacing: 10
property string currentWord: ""
TextEditVM {
id: textEditVM
Component.onCompleted: {
textEditVM.init(5)
}
}
Repeater {
id: repeater
model: 5
CharacterSelector {
property int index: 0
property string chararcter: " "
onSelectedCharChanged: {
chararcter = selectedChar;
if (selectedChar !== "") {
console.log("CharacterSelectors - Setting char at index", index, "to", selectedChar)
textEditVM.setChar(index, selectedChar)
// Force update the currentWord property
root.currentWord = textEditVM.getWord()
}
}
}
}
function getWord() : string {
return textEditVM.getWord();
}
}
(There is also some parent QML or C++ code that instantiates CharacterSelectors, passes textEditVM as vm, etc.)
TextEditVM (C++ / QUL side)
text_edit_vm.h
#pragma once
#include <QObject>
#include <QString>
#include <vector>
class TextEditVM : public QObject {
Q_OBJECT
Q_PROPERTY(QString word READ getWord WRITE setWord NOTIFY wordChanged)
public:
explicit TextEditVM(QObject *parent = nullptr);
QString getWord() const;
void setWord(const QString &w);
signals:
void wordChanged();
private:
QString m_word;
};
text_edit_vm.cpp
#include "text_edit_vm.h"
#include <QDebug>
TextEditVM::TextEditVM(QObject *parent) : QObject(parent), m_word("") {
qDebug() << "TextEditVM initialized";
}
QString TextEditVM::getWord() const {
qDebug() << "TextEditVM::getWord returning:" << m_word;
return m_word;
}
void TextEditVM::setWord(const QString &w) {
if (m_word != w) {
m_word = w;
qDebug() << "TextEditVM::setWord, new word =" << m_word;
emit wordChanged();
}
}
getWord() from the view model never runs (or returns empty) even though setChar() logs show the character was set. What am I missing? Is this a timing / delegate-creation issue, a problem exposing the C++ object to QML, or a QUL-specific string/notify issue?
As the characterselectors changed characters, they should be visible on the textdialog. But it didn't
textEditVMdoes not have asetCharmethod, only asetWordmethod.