Unsolved An array container to store sets of widget pointers?
-
I have two QTabWidgets, one to display a list of QTextEdit and another for a list of QLabels to display images. The two tabwidgets correspond to each other, so Qlabel1 will display the result of QTextEdit1, also I will have a processor widget attached to every QTextEdit/QLabel pairs for communication/logic.
Now I need an array container that can store everything into one place where I can retrieve them individually. I have found this answer to be almost what I'm looking for, but he uses QVector, which can only store one widget in the list, where I need to store three, something like this:
QVector< QTextEdit *, QLabel *, QWidget * > widgetsVector;
My second question is what indexing method should I use? To use the index number from their tab or give each sets an unique name? The answer above used the first one but I have also read that it will not work if I'm to have my tab movable across the tabwidget, which will reordered the index number.
-
@lansing said in An array container to store sets of widget pointers?:
QVector< QTextEdit *, QLabel *, QWidget * > widgetsVector;
C++ basics: all these classes are QWidgets, so simply use QVector<QWidget*>.
-
How do store and retrieve them? For example for QLabel3 in the vector?
-
@lansing Like anything else with a QVector?
vector.append(label); vector[0]; // Or how ever you want to access the elements in the vector. // You will need to cast the QWidget* to what it actually is // See https://doc.qt.io/qt-5/qobject.html
-
I don't think you understand my question. I want to store groups of three widgets, not one. Like this
{qtextedit1, qlabel1, processor1} {qtextedit2, qlabel2, processor2} {qtextedit3, qlabel3, processor3} {qtextedit4, qlabel4, processor4}
not this:
qtextedit1 qlabel1 processor1 qtextedit2 qlabel2 processor2
-
@lansing
QVector <QVector< QWidget * > > -
@lansing Then create a struct and put that struct into QVector:
struct Group { QTextEdit *edit; QLabel *label; QWidget *widget; }; QVector<Group> widgetsVector;
-
Thanks this looks to be it.
-
@jsulm +1 for using
struct
;-)