PDA

View Full Version : [not solved] QTableView with QSqlrelationaltable and foreign key



archqt
9th January 2011, 14:46
Hi,
here is the problem. I have 2 tables Person and Status, 2 views and a foreign key in Person to Status.
If i add new status in Status Table and after i go to Person, with the QSqlrelationalDelegate i can choose the status i want.
But if after i go back to Status view and add a new line Status, then i do :

if (m_model->relationModel(m_foreign)) m_model->relationModel(m_foreign)->select();
To update the delegate, so i can see the new value in the combobox, but...when i click on it. The new line is added on Person Table BUT WITH EMPTY FOREIGN KEY but i see nothing on the View. So i suppose the combobox used in delegate doesn't send the good id but why ? I tried lot of things. I can add other person only if the status were added first in Person Status. If the status is once added after i added first person then it doesn't work.
As there is no example that use 2 views and foreign key like this i don't know if it is possible doing it that way.
If i restart program i can add person but last status as it is already in Status Table before i add first Person.
Thanks for answer

archqt
9th January 2011, 18:35
With some tests, it seems that the delegate works fine. I try to look for another thing.

archqt
9th January 2011, 20:55
I do some tests and i found that this line return false and i don't know why :

sqlModel->setData(index,
childModel->data(childModel->index(currentItem, childEditIndex), Qt::EditRole),
Qt::EditRole);
But one thing strange is that there is also a beforeInsert(QSqlRecord&) signal ?
Can anymore help me.
Thanks

archqt
10th January 2011, 22:54
It is an internal bug of Qt. So my advice don't use QSqlRelationalTableModel. Do your own