Pointer Question related to QLineEdit
Hey Guys, I've got a simple pointer question related to QTextEdit. I have 18 QLineEdit boxes. I want to create an Array of QTextEdit pointers to point to the 18 instances of QTextEdit so that I can access them using an index rather then having to call each instance every time. When I do this, however, a runtime error is generated.
The 18 instances of QLineEdit
Code:
byte0Edit
->setObjectName
(QString::fromUtf8("byte0Edit"));
byte0Edit
->setGeometry
(QRect(177,
40,
31,
20));
byte1Edit
->setObjectName
(QString::fromUtf8("byte1Edit"));
byte1Edit
->setGeometry
(QRect(217,
40,
31,
20));
byte2Edit
->setObjectName
(QString::fromUtf8("byte2Edit"));
byte2Edit
->setGeometry
(QRect(257,
40,
31,
20));
Byte3Edit
->setObjectName
(QString::fromUtf8("Byte3Edit"));
Byte3Edit
->setGeometry
(QRect(297,
40,
31,
20));
byte6Edit
->setObjectName
(QString::fromUtf8("byte6Edit"));
byte6Edit
->setGeometry
(QRect(417,
40,
31,
20));
byte4Edit
->setObjectName
(QString::fromUtf8("byte4Edit"));
byte4Edit
->setGeometry
(QRect(337,
40,
31,
20));
byte7Edit
->setObjectName
(QString::fromUtf8("byte7Edit"));
byte7Edit
->setGeometry
(QRect(457,
40,
31,
20));
byte5Edit
->setObjectName
(QString::fromUtf8("byte5Edit"));
byte5Edit
->setGeometry
(QRect(377,
40,
31,
20));
byte13Edit
->setObjectName
(QString::fromUtf8("byte13Edit"));
byte13Edit
->setGeometry
(QRect(337,
70,
31,
20));
byte12Edit
->setObjectName
(QString::fromUtf8("byte12Edit"));
byte12Edit
->setGeometry
(QRect(297,
70,
31,
20));
byte10Edit
->setObjectName
(QString::fromUtf8("byte10Edit"));
byte10Edit
->setGeometry
(QRect(217,
70,
31,
20));
byte14Edit
->setObjectName
(QString::fromUtf8("byte14Edit"));
byte14Edit
->setGeometry
(QRect(377,
70,
31,
20));
byte8Edit
->setObjectName
(QString::fromUtf8("byte8Edit"));
byte8Edit
->setGeometry
(QRect(500,
40,
31,
20));
byte11Edit
->setObjectName
(QString::fromUtf8("byte11Edit"));
byte11Edit
->setGeometry
(QRect(257,
70,
31,
20));
byte15Edit
->setObjectName
(QString::fromUtf8("byte15Edit"));
byte15Edit
->setGeometry
(QRect(417,
70,
31,
20));
byte9Edit
->setObjectName
(QString::fromUtf8("byte9Edit"));
byte9Edit
->setGeometry
(QRect(177,
70,
31,
20));
byte16Edit
->setObjectName
(QString::fromUtf8("byte16Edit"));
byte16Edit
->setGeometry
(QRect(457,
70,
31,
20));
byte17Edit
->setObjectName
(QString::fromUtf8("byte17Edit"));
I then declare an array of QLineEdit Pointers. And point at the 18 instances of QLineEdit.
Code:
LineEditArray[0] = ui.byte0Edit;
LineEditArray[1] = ui.byte1Edit;
LineEditArray[2] = ui.byte2Edit;
LineEditArray[3] = ui.Byte3Edit;
LineEditArray[4] = ui.byte4Edit;
LineEditArray[5] = ui.byte5Edit;
LineEditArray[6] = ui.byte6Edit;
LineEditArray[7] = ui.byte7Edit;
LineEditArray[8] = ui.byte8Edit;
LineEditArray[9] = ui.byte9Edit;
LineEditArray[10] = ui.byte10Edit;
LineEditArray[11] = ui.byte11Edit;
LineEditArray[12] = ui.byte12Edit;
LineEditArray[13] = ui.byte13Edit;
LineEditArray[14] = ui.byte14Edit;
LineEditArray[15] = ui.byte15Edit;
LineEditArray[16] = ui.byte16Edit;
LineEditArray[17] = ui.byte17Edit;
I then try to set the text of the QLineEdit. This is where the error is generated on the first call to setText.
Code:
for(int i = 0; i < 18; i++)
{
LineEditArray[i]->setText("");
}
I can tell I'm overlooking something. Any ideas? Thanks.
Re: Pointer Question related to QLineEdit
Why you not use a model? QStandardItemModel to fille a QTreeView
2 columns column 0 as label and 1 editable to data ... like QDesigner Propriety...
Your way ....
Code:
enum { NumComandButton = 13 }; /* on header */
/* valid action */
QList<QAction *> actionlist = Layer->MainActions();
Q_ASSERT ( actionlist.size() == NumComandButton );
for (int i = 0; i < NumComandButton; ++i) {
tbutton[i]->SetAction(actionlist[i]);
tbutton[i]->setEnabled(true);
}
The model sample:
write new model 2 column
Code:
{
bold_base_font = qApp->font();
flags_yes = Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
flags_no = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
bold_base_font.setBold ( true );
Hitem1->setData(bold_base_font,Qt::FontRole);
Hitem2->setData(bold_base_font,Qt::FontRole);
model->setHorizontalHeaderItem(0,Hitem1);
model->setHorizontalHeaderItem(1,Hitem2);
model->invisibleRootItem()->appendRow(ReadOnlyValue("epoche",tr("ID:")));
model->invisibleRootItem()->appendRow(TagValue("cat",tr("Category:")));
model->invisibleRootItem()->appendRow(TagName("tit_",tr("Title:"),5));
model->invisibleRootItem()->appendRow(TagName("desc_",tr("Description:"),15));
model->invisibleRootItem()->appendRow(TagName("note_",tr("Note:")));
model->invisibleRootItem()->appendRow(TagName("autor_",tr("Autor:")));
model->invisibleRootItem()->appendRow(TagValue("active",tr("Priority:")));
model->invisibleRootItem()->appendRow(TagValue("start",tr("Start time:")));
model->invisibleRootItem()->appendRow(TagValue("stop",tr("Stop time:")));
model->invisibleRootItem()->appendRow(TagValue("worksource",tr("Source work:")));
model->invisibleRootItem()->appendRow(TagValue("bgcolor",tr("Background color:")));
return model;
}
/* each line row */
QList<QStandardItem
*> PageXmlHandler
::TagValue( const QString shortname ,
const QString HumanName
){
noedit->setFlags(flags_no);
noedit->setData(bold_base_font,Qt::FontRole);
noedit->setData(grundierung,Qt::BackgroundColorRole);
QList<QStandardItem *> diritto;
Hitem2->setFlags(flags_yes);
Hitem2->setToolTip ( shortname );
Hitem2->setData(shortname,TAGID);
Hitem2->setData(2,T_FORMAT);
Hitem2->setData(Current->Root_Tag(shortname),OLDVALUE);
diritto.append(noedit);
diritto.append(Hitem2);
return diritto;
}
at end QTreeView setmodel editable and grab model back data....