| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 3 | |
Hi all!
I have problem to change value in table ( only in _table_ but not in
_database_ ).
For example, for each empty value set new value "EMPTY!":
model = new QSqlQueryModel;
model -> setQuery ( "SELECT * FROM collection" );
model -> setHeaderData ( 2, Qt::Horizontal, tr ( "Name" ) );
model -> setHeaderData ( 3, Qt::Horizontal, tr ( "Artist" ) );
model -> setHeaderData ( 4, Qt::Horizontal, tr ( "Album" ) );
for (int i = 0; i < model->rowCount(); ++i) { // for all empty value
QSqlRecord record = model->record(i);
QString salary = record.value("title").toString();
if ( salary.isEmpty() ) {
std::cout << "OLD VALUE: " << salary . toStdString() <<
std::endl; // check old value
salary = "EMPTY!";
record.setValue("title", salary); // set new value
std::cout << "NEW VALUE: " <<
record.value("title").toString().toStdString() << std::endl; // check
new value
}
}
model->submit();
Value change only in console output, but in table still old value.
Any ideas?
--
[ signature omitted ]
Hi all!
I have problem to change value in table ( only in _table_ but not in
_database_ ).
For example, for each empty value set new value "EMPTY!":
model = new QSqlQueryModel;
model -> setQuery ( "SELECT * FROM collection" );
model -> setHeaderData ( 2, Qt::Horizontal, tr ( "Name" ) );
model -> setHeaderData ( 3, Qt::Horizontal, tr ( "Artist" ) );
model -> setHeaderData ( 4, Qt::Horizontal, tr ( "Album" ) );
for (int i = 0; i < model->rowCount(); ++i) { // for all empty value
QSqlRecord record = model->record(i);
QString salary = record.value("title").toString();
if ( salary.isEmpty() ) {
std::cout << "OLD VALUE: " << salary . toStdString() <<
std::endl; // check old value
salary = "EMPTY!";
record.setValue("title", salary); // set new value
std::cout << "NEW VALUE: " <<
record.value("title").toString().toStdString() << std::endl; // check
new value
}
}
model->submit();
Value change only in console output, but in table still old value.
Any ideas?
--
[ signature omitted ]
Am Samstag, 12. April 2008 schrieb Alex J. Ivasyuv: > I have problem to change value in table ( only in _table_ but not in > _database_ ). <snip> > Any ideas? I don't think that you will gain more helping answers by resending the same message every day... Arnold, stuck with some model-view-problems myself... -- [ signature omitted ]
Attachment:
signature.asc
Description: This is a digitally signed message part.
> From: Alex J. Ivasyuv [mailto:industral@xxxxxxxxx]
> Sent: Sunday, 13 April 2008 03:18
>
> Hi all!
>
> I have problem to change value in table ( only in _table_ but not in
> _database_ ).
> For example, for each empty value set new value "EMPTY!":
>
> model = new QSqlQueryModel;
> model -> setQuery ( "SELECT * FROM collection" );
> model -> setHeaderData ( 2, Qt::Horizontal, tr ( "Name" ) );
> model -> setHeaderData ( 3, Qt::Horizontal, tr ( "Artist" ) );
> model -> setHeaderData ( 4, Qt::Horizontal, tr ( "Album" ) );
>
> for (int i = 0; i < model->rowCount(); ++i) { // for all
> empty value
> QSqlRecord record = model->record(i);
> QString salary = record.value("title").toString();
> if ( salary.isEmpty() ) {
> std::cout << "OLD VALUE: " << salary . toStdString() <<
> std::endl; // check old value
> salary = "EMPTY!";
> record.setValue("title", salary); // set new value
> std::cout << "NEW VALUE: " <<
> record.value("title").toString().toStdString() << std::endl; // check
> new value
> }
> }
> model->submit();
>
> Value change only in console output, but in table still old value.
>
> Any ideas?
Hi Alex,
QSqlQueryModel doco says it is read-only. You need to use QSqlTableModel instead.
Hope that helps,
Tony Rietwyk
--
[ signature omitted ]