K
K
KaterSpieler2012-07-03 12:52:14
SQL
KaterSpieler, 2012-07-03 12:52:14

why is there an error when working with tablerelationmodel in QT and SQLite? (resolved)

created 2 tables like this

Читатели:
Код SQL
CREATE TABLE readers(
    id             INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
    id_book      INTEGER,
    age          INTEGER,
    FIO          VARCHAR(10),
    FOREIGN KEY(id_book) REFERENCES books(id)
);
 

Книги:
Код SQL

CREATE TABLE books(
    id          INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE,
    price      INTEGER,
    COUNT     INTEGER,
    title       VARCHAR(10)
);



Then this code

QSqlRelationalTableModel* model = new QSqlRelationalTableModel(0); model->setTable("readers"); model->setRelation(1,QSqlRelation("books", "id_book", "title")); //ASSERT тут ассерт..... model->select(); model->setEditStrategy(QSqlTableModel::OnManualSubmit); ui->tableView->setModel(model);

and then the error

Runs D:\projects\QT\TEST_DB-build-desktop\debug\TEST_DB.exe…
ASSERT: "idx >= 0 && idx < s" in file ..\..\include/QtCore/ ../../../../../../ndk_buildrepos/qt-desktop/src/corelib/tools/qvarlengtharray.h, line 107
D:\projects\QT\TEST_DB-build-desktop\debug \TEST_DB.exe for

If I remove the line with setrelation - everything is fine

Everything is simple - the names of the related fields must be the same

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
maquefel, 2012-07-04
@maquefel

Try those instead of QSqlRelation("books", "id_book", "title") - new QSqlRelation("books", "id", "title").

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question