PDA

View Full Version : Selected Record into TextEdit...



Nefastious
21st October 2009, 19:21
Hi guys,

Have a bit of a problem here, the following code doesn't work properly (it doesn't copy the value of certain fields of a user-selected record unto a QTextEdit):


printviewdialog *print = new printviewdialog;
print->exec();
//Declaring an item selection which we will use to see which row the user has selected
QItemSelection selection = ui->View->selectionModel()->selection();
QList<int> rows;
foreach ( const QModelIndex & index, selection.indexes() ) {
rows.append( index.row() );
}
qSort( rows );
for( int i = rows.count() - 1; i >= 0; i -= 1 ) {
QString name = model->record(i).value("name").toString();
print->textEdit->append(name);
}
if (print->Accepted) {
print->textEdit->print(print->printer);
}

What am I doing wrong? Code samples would be largely appreciated.

Thanks in advance,

Nefastious :confused:

wysota
21st October 2009, 23:58
If you want help, it would be good to actually provide some specific details. Statements such as "properly" and "certain fields" do not mean much.

Nefastious
22nd October 2009, 09:34
Well, the QTextEdit simply shows up empty and all of the fields should be copied into it (in the sample above only the value of the "name" field is copied)...

wysota
22nd October 2009, 10:35
Did you inspect that "QString name" actually contains the values you want?

I'd also use QItemSelectionModel::selectedRows() instead of that mambo-jambo with sorting indexes.

Nefastious
23rd October 2009, 17:57
Well, could please give me some sample code of how to use the QItemSelection::selectedRows()?

Thanks in advance