-
Bug
-
Resolution: Out of scope
-
P3: Somewhat important
-
4.6.2
-
None
-
Windows XP SP3
Hello again, I attached a file of my project. I have two tables. Table successfully created (not the problem). Scripts their creation:
"CREATE TABLE IF NOT EXISTS section("
"id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"
"name INT)"
"CREATE TABLE IF NOT EXISTS goods("
"id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,"
"section_id INTEGER NOT NULL CONSTRAINT fk15_section_id REFERENCES section(id) ON DELETE CASCADE,"
"count DOUBLE)"
I want to create a table model which goods would be referred to the section and display the data correctly references a column (by setRelation ()) so that you can find out what id of the selected entries in the editable element field section_id table goods. Such as a list of entries in the table section:
0 Toys
1 Products
2 Computers
and table goods :
0 1 5
1 1 10
2 2 15
after this goods->setRelation(1,QSqlRelation("section","id","name"));
then the table looks goods :
0 Products 5
1 Products 10
2 Computers 15
Then, if a table entry goods with id = 0 is selected Products of the Products that id in the table section is equal to 1. My first question is: how do I know this piece of id?
Here and there is a problem. If I make a filter so goods.setFilter (id = 1) and then goods.select (), then I get 0 records. If I make it so goods.setFilter(name = 'Products') then I get 2 entries. And I only need one to see id. How does it know?
I decided to try another way. Write the editor of this record, priobrazovat it QComboBox, learn currentIndex (), and then create another table section and there on this line = currentIndex () see id. I did so:
QItemDelegate dlg1;
QWidget *w1 = dlg1.createEditor(0,QStyleOptionViewItem(),goods->index(0,1));
QComboBox *cb1 = static_cast<QComboBox *>(w1);
Somehow, even after setRelation () delegates in a column of the table goods do not become QComboBox. They belong to QExpandingLineEdit, but the assistant says:
//void QSqlRelationalTableModel::setRelation ( int column, const QSqlRelation & relation ) [virtual]
//Lets the specified column be a foreign index specified by relation.
then why w1 = QExpandingLineEdit ?
This is my second question. The project file is attached. Many thanks in advance.