Unsolved Editing data in QStandardItemModel (and tableview)
-
@SGaist
Hi,
My bad. I ment the db. -
ok, this is a whole different matter.
You have to connect a slot to dataChanged of the model and execute a query to update the db
-
@VRonin
I'm trying to implement the slot and query.
I have the following for connect:connect(fixModel, SIGNAL(fixModel->dataChanged),this, SLOT(refreshDb()));
For updating the db:
QSqlQuery query_update; query_update.prepare ("UPDATE Items SET ID = :fixID"); query_update.bindValue (":fixID",ID);
Assuming this works (wasn't able to test it yet). To make this work, I need to get the ID from column 0 of tableview. I try to use this:
QModelIndex fixIndex(index.model ()->index.fixRow(),0,index.parent ()); qDebug() << fixIndex.data (Qt::DisplayRole); QVariant vfix(fixIndex.data(Qt::DisplayRole)); fixID = vfix.toString (); qDebug() << "fixID: " << fixID;
but the first line gives me an error:
C:\Programming\Projects\Folkfriends_1_0\fixdb.cpp:124: error: '(& index)->QModelIndex::model()->QAbstractItemModel::index' does not have class type
QModelIndex fixIndex(index.model ()->index.fixRow(),0,index.parent ());
^
What did I miss?
Thank you. -
Are you in a hurry? looks like it...
connect(fixModel, SIGNAL(fixModel->dataChanged),this, SLOT(refreshDb()));
makes no sense. the SIGNAL argument is completely wrong and both miss the arguments...index.model ()->index
makes no sense.index.row()
is what you need -
@VRonin
I think I need to emit an itemChanged signal and it has to receive by the function which will process the db update.
I came up with the following, but it is still not working:connect(fixModel ,SIGNAL(itemChanged), this, SLOT(updateItem(itemChanged)));
How can I emit the itemChanged signal correctly? I get the error message
"QObject::connect: Parentheses expected, signal QStandardItemModel::itemChanged in ..\Folkfriends_1_0\fixdb.cpp:107"
Thank you -
Both your SIGNAL and SLOT macro content is wrong.
You really should use the syntax as described here. It will avoid such errors.
-
-
QVector< QVector<QString> > m_gridData;
-
@SGaist
I try to understand how to work this QVector. I believe your code includes 2 QVectors. I think what I'm trying to do is adding 2 int (the row and col) to the vector plus the QString stored at the location defined by the 2 int. Would you please show me how to do that? Thank you. -
@gabor53
Hi To get the string, you need to know row, col so why you need to store it with string ?Anyway, you can use a struct
struct MyData {
QString data;
int col;
int row;
};QVector< QVector<MyData> > m_gridData;
Notice !
unlike
QString m_gridData[ROWS][COLS];QVector is EMPTY to start with so you must append before you can access.
-
Or if you know the initial size your can fill your QVector of QVector are startup.