PDA

View Full Version : mapper stop after upgrade to 4.4.3



SunnySan
16th October 2008, 18:23
I have upgraded QT from 4.4.0 to the latest 4.4.3(of Nokia)

and the QDataWidgetMapper doesn't seem to work anymore!!

is anybody had similar pb??
or is it that my code is missing something which only work with the previous version?

I load the database to display a list in the table "ui.tableView_PL" (this still work and display the table).
and I use mapper to show some info into different labels. but nothing is display on these labals anymore.

It worked before the upgrade so I am a bit puzzled...



void mainwindow::loadProgamListFromDB(QString indexPL, bool addnewElement) {


// loAD table
QSqlQueryModel *modelFromSql = new QSqlQueryModel();
QString sqlString =
"SELECT id,name, capacity,duration, position FROM plandfile WHERE pl_id="
+ indexPL + " ORDER BY position";//ORDER BY id ASC ";
modelFromSql->setQuery(sqlString);
ui.tableView_PL->setModel(modelFromSql);
modelFromSql->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
modelFromSql->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
modelFromSql->setHeaderData(2, Qt::Horizontal, QObject::tr("Capacity"));
modelFromSql->setHeaderData(3, Qt::Horizontal, QObject::tr("Duration"));
modelFromSql->setHeaderData(4, Qt::Horizontal, QObject::tr("Position"));

ui.tableView_PL->show();

int numberofvalues = modelFromSql->rowCount();
if (addnewElement) {
selectedRowIndex = (numberofvalues - 1);//row to be highlighted // when add Pause selected row should last row
}
ui.tableView_PL->selectRow(selectedRowIndex);//row to be highlighted

//sizes of the columns
ui.tableView_PL->setColumnWidth(0, 40);//size for index
ui.tableView_PL->setColumnWidth(1, 300);//size for name
ui.tableView_PL->setColumnWidth(4, 50);//size for position
ui.tableView_PL->hideColumn(4);//hide position column
ui.tableView_PL->hideColumn(0);//hide index column

ui.tableView_PL->setFocus();

QString message=" numberofvalues: "+QString::number(numberofvalues,10)
+" selectedRowIndex: "+QString::number(selectedRowIndex,10);
QMessageBox::about(this, tr("numberofvalues"), message);// need <QtGui>

QDataWidgetMapper *mapper = new QDataWidgetMapper(this);
mapper->setModel(modelFromSql);
mapper->setItemDelegate(new QSqlRelationalDelegate(this));
mapper->addMapping(ui.label_plandfileID, 0);//map label3 to the first column
mapper->addMapping(ui.label_plandfileName, 1);
mapper->addMapping(ui.label_position, 4);

mapper->setCurrentIndex(selectedRowIndex);

connect(ui.tableView_PL->selectionModel(), SIGNAL(currentRowChanged (QModelIndex,QModelIndex)), mapper, SLOT(setCurrentModelIndex(QModelIndex)));
}

janus
16th October 2008, 19:47
Hi,

RelationalDelegate on a QueryModel - does that work? Another idea try mapper->toFirst() after addMapping.

SunnySan
17th October 2008, 10:50
I ve tried mapper-> tofirst(); but still nothing

RelationalDelegate on a QueryModel - does that work?
It did with 4.4.0 , I may have to try with another model type...

janus
17th October 2008, 12:20
Hi,

but how does the RelationalDelegate know to resolve the foreignkey with a QueryModel? :confused:

Afaik it should then be something like this:


mapper->setModel(MyQSqlRelationalTableModel->relationModel(int column));

SunnySan
17th October 2008, 12:52
I try many things but mapper doesn't seem to work anymore with 4.4.3

came back with 4.4.0 . and... it s back to normal, working fine.


anybody knows how to submit a bug to Nokia(QT)???

SunnySan
20th October 2008, 11:26
I have check qt bug
it seems that this happened to others as well.
bug submitted but it is not a priority :( .
i'll stay with QT4.4.0 for now, and upgrade later for next release

SunnySan
6th November 2008, 12:50
I have fix my problem using this code instead



void mainwndow::updateQlabel(const QModelIndex &index){
//try to go around the QT bug

int row =index.row();

ui.label_toupdate->setText(modelFromSql->record(row).field("id").value().toString());



with "modelFromSql" a private member (QSqlQueryModel) declare in the .h
and


mainwndow::mainwndow(QWidget *parent) :
QMainWindow(parent)
,modelFromSql()//to carry current table model
{.......
...


I hope this help others