PDA

View Full Version : Update a row



dragon
15th January 2006, 20:57
Hello anyone,

In a QTableWidget you can update a item.
But is it possible to update a row when you click on the row in QTable through a QDialog.
I want to see the items in a row in the QLineEdits in QDialog.


void ContactWindow::edit(QTableWidgetItem *item )
{
int row;
contactTable->selectRow(row);

{
contactDialog dlg(this);
dlg.leBedrijf->setText(item->text());
dlg.leContact->setText(item->text());
dlg.leTel->setText(item->text());
if(dlg.exec() == QDialog::Accepted) {
}

return;
}
}

}


There must be some changes in the code it only display one item.

jacek
15th January 2006, 22:37
Shouldn't there be something like this for every column?
QTableWidget *item = contactTable->item( row, 0 );
QString text;
if( item != 0 ) {
text = item->text();
}
dlg.leContact->setText( text );

dragon
16th January 2006, 18:56
QTableWidget *item = contactTable->item( row, 0 );
QString text;
if( item != 0 ) {
text = item->text();
}
dlg.leContact->setText( text );


I have tried is pieces off code in my edit function but it gives a error text() is no member off Class QTableWidget.

I have change the code because off the error.


void ContactWindow::edit(QTableWidgetItem *item )
{
int row;
contactTable->selectRow(row);

contactTable->item( row, 0 );
QString bedrijf;
if( item != 0 ) {
bedrijf = item->text();
}
contactTable->item( row, 1 );
QString contact;
if( item != 0 ) {
contact = item->text();
}
contactTable->item( row, 2 );
QString tel;
if( item != 0 ) {
tel = item->text();
}

{
contactDialog dlg(this);
dlg.leBedrijf->setText( bedrijf);
dlg.leContact->setText( contact );
dlg.leTel->setText( tel );
if(dlg.exec() == QDialog::Accepted) {
}

}
}


It still not working when i click on the row in contactTable i see in the Dialog in the lineEdits the same items from the first column.

Example off my Dialog LineEdits:

Bedrijf: TMC
Contact: TMC
Tel: TMC

jacek
16th January 2006, 20:28
I have tried is pieces off code in my edit function but it gives a error text() is no member off Class QTableWidget.
It should be QTableWidgetItem instead of QTableWidget.


I have change the code because off the error.
[...]
It still not working when i click on the row in contactTable i see in the Dialog in the lineEdits the same items from the first column.
Because you always retrieve data from the same item.

dragon
16th January 2006, 20:44
I have change the QTableWidget into QTableWidgetItem.
In my Dialog it display nothing in LineEdits.


void ContactWindow::edit(QTableWidgetItem* )
{
int row;
contactTable->selectRow(row);

QTableWidgetItem *item = contactTable->item( row, 0 );
QString bedrijf;
if( item != 0 ) {
bedrijf = item->text();
}
QTableWidgetItem *contactitem = contactTable->item( row, 1 );
QString contact;
if( contactitem != 0 ) {
contact = contactitem->text();
}
QTableWidgetItem *telitem = contactTable->item( row, 2 );
QString tel;
if( telitem != 0 ) {
tel = telitem->text();
}

{
contactDialog dlg(this);
dlg.leBedrijf->setText( bedrijf);
dlg.leContact->setText( contact );
dlg.leTel->setText( tel );
if(dlg.exec() == QDialog::Accepted) {
}

}
}

jacek
16th January 2006, 21:09
I have change the QTableWidget into QTableWidgetItem.
In my Dialog it display nothing in LineEdits.
You didn't initialize the row variable.

dragon
16th January 2006, 21:51
What do you mean with didn't initialize the row variable.
I have initialize the row varible in the begin of the function.



int row; // You mean this ?
contactTable->selectRow(row);

QTableWidgetItem *item = contactTable->item( row, 0 );
QString bedrijf;
if( item != 0 ) {
bedrijf = item->text();
}

jacek
16th January 2006, 22:07
int row; // You mean this ?
Yes, it has some random value now. You have to set it to the current row number.

yop
16th January 2006, 22:21
I have initialize the row varible in the begin of the function.Writing something like
int foo;is declaring a variable, that is you are saving memory space for that variable but the memory has something in it that you don't know and depends on what used that memory space before. Initializing a variable is assigning a value to it when you declare it like
int foo=0;and now you are certain that foo==0 and not foo==whatever happens to be in the memory I just allocated ;)

dragon
17th January 2006, 18:11
Thanks jacek and yop for your answer and time.
The problem is solved.
I did only a last modifaction on the first line in my function..
If i did:
int row = 0; with the combination selectRow(row) the Dialog shows only the first row.
Here the replacement off the code;


int row = contactTable->currentRow();


Thanks and Bye.