I am trying to make a variable number of pages on a QToolbox with a set number of QLineEdit fields. The number of pages and their names is determined by a vector of strings. Each page of the QToolbox has two QLineEdits. After the fillToolbox function is called, the printExtractedData function is called. As stated in the name I am just looking to print the std::string form of the data.
void fillToolbox(vector <string> toolboxLabels){
QLineEdit *l1, *l2;
QGridLayout *gridLayout;
for (int i = 0; i < numEntries; i++)
{
gridLayout = new QGridLayout;
l1 = new QLineEdit;
l2 = new QLineEdit;
QFrame *frm = new QFrame;
QLabel *l1Label = new QLabel("Field 1:");
QLabel *l2Label = new QLabel("Field 2:");
gridLayout->addWidget(l1Label, 0, 0);
gridLayout->addWidget(l1, 0, 1);
gridLayout->addWidget(l2Label, 1, 0);
gridLayout->addWidget(l2, 1, 1);
frm->setLayout(gridLayout);
ui.myToolBox->addItem(frm, QString(toolboxLabels[i].c_str()));
}
}
User adds input to LineEdit fields.
void printExtractedData() {
int numPages = ui.myToolBox->count();
cout << numPages << endl;
for (int i = 0; i < numPages; i++)
{
string key = ui.myToolBox->itemText(i).toLocal8Bit().constData();
if (QWidget* wg = qobject_cast<QWidget*>(ui.myToolBox->widget(i))) {
QLayout *layout = wg->layout();
for (int j = 0; j < layout->count(); j++)
{
if (QLineEdit* le = qobject_cast<QLineEdit*>(layout->itemAt(j)->widget())) {
string text = le->text().toLocal8Bit().constData();
cout << le <<endl;
}
}
}
}
}
When I insert a two element list, I receive the output:
2
00000245E5A77260
00000245E5A76FE0
00000245E5A0A510
00000245E5B17540
The desired result is a printed string of the content from the QLineEdit fields.
Any help or advice would be appreciated.