In hypothetisches Beispiel habe ich eine C++ Komponente -Wie C++ Komponente in QML instanziiert - MIT Parameterized Constructor
class Board : public QObject
{
Q_OBJECT
public:
//Q_PROPERTYs go here
explicit Board(int rows, int columns)
{
matrix = std::vector<int>(rows, std::vector<int>(columns, 0));
}
~Board()
{
matrix.clear();
}
Q_INVOKABLE void checkAndUpdateAdjecentCells(int row, int column);
//setters and getters here.
signals:
void matrixUpdated();
private:
Board(QObject *parent) = default; //i intend to do this.
Board(Board& b) = delete;
int nRows_, nCols_;
std::vector<std::vector> matrix;
};
in main()
wie registriert -
qmlRegisterType<Board>("SameGameBackend", 1, 0, "BubbleBoard");
Frage
Wie instanziiere ich dies in QML, so dass der parametrisierte Konstruktor aufgerufen wird?
Expected QML-Code -
BubbleBoard{
id: bboard
rows: 10
columns: 10
}
Wir werden diese Frage erweitern können Initialisiererliste aufzunehmen. Hatte nRows_
und nCols_
const int
gewesen, hätte Konstruktor
explicit Board(int rows, int columns):nRows_(rows), nCols_(columns){}
Ist es möglich, solche Bauteile von innen QML zu instanziiert?
AFAIK, gibt es keine solche Funktion. Siehe die Antwort unten. – Tarod