PDA

View Full Version : EDITED: Representing an Array REDUX!!!!



bobby
15th November 2009, 22:06
Hello,
I've got the official book: http://qt.nokia.com/developer/books/cpp-gui-programming-with-qt-4-2nd-edition, but I've come to part where I'm not sure which way to go.

I've got an array of 100 integers that are 3 integers long. I've setup my inputmasks on my lineEdits to be able to control this, so data sanitation is already handled. I'm trying to figure out the best way to both display this data, as well as edit it.


Is it possible to create pointers of lineEdits, put them in a QList container, and display them as well as access them through for() loops?
Is it possible to create an array within another class, and simply have 100 line edits point to said array. lineEdit00 points to numbers[0]?
Am I missing something?


Any help would be great. Thanks for such a nice forum to ask questions.
-bobby


for(int i = 0; i < 100; i++)
{
// Setup the proper label
if( i < 10)
{
labelPtr = new QLabel(tr("0%1").arg(i));
}else{
labelPtr = new QLabel(tr("%1").arg(i));
}

// Now the Address Cell
lePtr = new QLineEdit();
lePtr->setInputMask("999");
// if it's cell 00 make uneditable
if(i < 1)
{
lePtr->setText("001");
lePtr->setReadOnly(true);
}
memAddr.append(lePtr);

}

// Fill in the layout and display it
for( int i = 0; i < 100; i++)
{
layout->addWidget(memAddr.at(i));
}

window->setLayout(layout);
window->show();
EDIT:
Ok so I put my line edits into a QList, and I'm going to call them. my idea is that I have to use a forloop similar to the one I did, but with the addition to the labels as well.
I really need to know how to take something like this that I pulled off, and put it into my application. Do I stick everything into the mainWindow.cpp (implementation) or do I make a new class, I really don't know.

Another thought is to promote a groupbox into a "myGroupBox" and have the code run in there, but I'm really not clear how to do that, even with the help of Google.

-Bobby

calhal
15th November 2009, 23:02
Take a look at QTableView and QTableWidget classes, maybe this is what you need(?)

wysota
16th November 2009, 09:41
I suggest you take a look at the answer you have already been given.

bobby
17th November 2009, 06:25
Thanks guys!
I ended up putting the lineEdits into a QList of lineEdit pointers and then I added them into a grid layout row by row.

It may not be the best way, but it definitely worked. I think I would have been better off customizing a widget for my use, but I simply don't know how, so a QGridLayout of labels and lineEdits worked.

Thanks again!

wysota
17th November 2009, 09:02
Did you try QTableWidget?


QTableWidget *table = new QTableWidget(100,100);
for(int r = 0; r < 100; ++r)
for(int c = 0; c < 100; ++c)
table->item(r,c)->setText(QString::number(qrand()%1000));
table->show();