SunnySan
16th October 2008, 17: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)));
}
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)));
}