PDA

View Full Version : Record update windowd entered data saving



MarkoSan
5th January 2006, 10:59
I have an QSqlTabelModel filled with data from three sql tables. When I press in customer browser button "Insert record" or "Change record", mthe update record window show, which contain several QLineEdit widgets. How do I save entered data into database? My exact question is, how to convert every QLineEdit.text() into corespoding record field and then save it?



const int INSERT_RECORD_AT_END=-1;

QSqlRecord cDataRecord;

cDataRecord.setValue("SIFRA", m_pUpdateWindow->GetCustomerID()->text());
cDataRecord.setValue("DS", m_pUpdateWindow->GetTaxNumber()->text());
cDataRecord.setValue("PRIIMEK", m_pUpdateWindow->GetSurname()->text());
cDataRecord.setValue("IME", m_pUpdateWindow->GetName()->text());
//cDataRecord.setValue("ULICA", m_pUpdateWindow->GetStreetID()->text());
cDataRecord.setValue("STEVILKA_ULICE", m_pUpdateWindow->GetStreetNumber()->text());
cDataRecord.setValue("POSTA_STEVILKA", m_pUpdateWindow->GetZipCode()->text());

if(m_pTableModel->insertRecord(INSERT_RECORD_AT_END, cDataRecord))
{
QSqlError error=m_pTableModel->lastError();
if(error.type()!=QSqlError::NoError)
{
qDebug() << m_pTableModel->query().lastQuery();
} // if
} // if

Is it maybe problem in insertRecord paramaters?

wysota
5th January 2006, 11:14
QSqlRecord rec;
rec.setValue("id", lineedit1->text());
rec.setValue("name", lineedit2->text());
rec.setValue("address", lineedit3->text());

//...
model->insertRecord(-1, rec);

MarkoSan
5th January 2006, 11:17
QSqlRecord rec;
rec.setValue("id", lineedit1->text());
rec.setValue("name", lineedit2->text());
rec.setValue("address", lineedit3->text());

//...
model->insertRecord(-1, rec);
Ok, but how does Qt knows which table write to? Or, if i change the name of field with sql administrator, how to handle that kind of changes?

sunil.thaha
5th January 2006, 11:24
Well your model knows. Don't they ?
Your model1 should be some what like this


QSqlTableModel *model = new QSqlTableModel;
model->setTable("employee");

MarkoSan
5th January 2006, 11:25
Well your model knows. Don't they ?
Your model1 should be some what like this


QSqlTableModel *model = new QSqlTableModel;
model->setTable("employee");


Ahaaaam, there is a connection, I see now. :D Thank you. :D

MarkoSan
5th January 2006, 13:14
Hwo do I then convert data types (QLineEdit.text() returns QString) into SQL data types?

wysota
5th January 2006, 14:35
What kind of fields? Doesn't providing them as strings work?

MarkoSan
5th January 2006, 14:36
Nope, it adds a field, I can see that, but record that wass added is empty. In sql database scheme i have BIGINT(20), VARCHAR(255) and so on. Do I need conversion at all or is there something else wrong? Or, how do I refresh the table?

wysota
5th January 2006, 14:46
You shouldn't need any conversions. Maybe you should try using the version of setValue with field indexes and not field names.

MarkoSan
6th January 2006, 07:21
God damn, I tried both setValue versions, I took a look at sql statement, which executes, all without errors (QSqlError returns NoError). insertRecord statement returns TRUE (which is by the docs OK), but data are still not visible. Any other idea??

wysota
6th January 2006, 09:10
Are they inserted into the database and not visible in the application or not inserted at all? What happens if you execute the same query "by hand"?

MarkoSan
6th January 2006, 09:23
Well, i got the statement:


QSqlQuery::lastQuery returned {"SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.I ME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_k raja FROM stranka,u" size=217}


from the code:


QSqlRecord cDataRecord;

cDataRecord.setValue(QString("SIFRA"), m_pUpdateWindow->GetCustomerID()->text());
cDataRecord.setValue(QString("DS"), m_pUpdateWindow->GetTaxNumber()->text());
cDataRecord.setValue(QString("PRIIMEK"), m_pUpdateWindow->GetSurname()->text());
cDataRecord.setValue(QString("IME"), m_pUpdateWindow->GetName()->text());
//cDataRecord.setValue("ULICA", m_pUpdateWindow->GetStreetID()->text());
cDataRecord.setValue(QString("STEVILKA_ULICE"), m_pUpdateWindow->GetStreetNumber()->text());
cDataRecord.setValue(QString("POSTA_STEVILKA"), m_pUpdateWindow->GetZipCode()->text());
if(m_pTableModel->insertRecord(INSERT_RECORD_AT_END, cDataRecord))
{
QSqlError error=m_pTableModel->lastError();
if(error.type()!=QSqlError::NoError)
{
qDebug() << m_pTableModel->query().lastQuery();
} // if
} // if


There is no INSERT statement at all, what the heck is going on??

wysota
6th January 2006, 09:27
Try calling submit() or submitAll() on the model.

MarkoSan
6th January 2006, 09:37
Same result, empty record added to table, when I reopen the window, this empty record is not shown, so I neither does add empty neither filled record to database. Is maybe problem in QSqlDelegate?

wysota
6th January 2006, 21:55
Maybe the problem is with MySQL 5.0?

Did you try debugging to see if Qt even tries to fill those fields?

MarkoSan
6th January 2006, 22:26
As i posted earlier, I think the statement:
QSqlQuery::lastQuery returned "SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.I ME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_k raja FROM stranka,u"size=217
,which is created in method insertRecord is not correct.

Since I am total newbie in SQL, am I right or not?

It seems, but it is not logical, that method insertRecord does not create an SQL statment, but it should, as I understand the whole thing.

Or maybe, in the docs there is definition of method:


bool QSqlTableModel::insertRecord ( int row, const QSqlRecord (http://www.qtcentre.org/forum/qsqlrecord.html) & record )
The statement in my project is:


if(m_pTableModel->insertRecord(INSERT_RECORD_AT_END, cDataRecord))
cDataRecord is declared as:


QSqlRecord cDataRecord;
As far as I can see, the second parameter is reference to sql record, but i pass like insertRecord(-1, cDataRecord), as seen earlier. Is this ok or not?

MarkoSan
8th January 2006, 13:50
No one has idea????

jacek
8th January 2006, 15:19
Try this(note the "!"):
if( ! m_pTableModel->insertRecord( INSERT_RECORD_AT_END, cDataRecord ) )
{
qDebug() << m_pTableModel->lastError().text();
qDebug() << m_pTableModel->query().lastQuery();
}

MarkoSan
8th January 2006, 15:36
Try this(note the "!"):
if( ! m_pTableModel->insertRecord( INSERT_RECORD_AT_END, cDataRecord ) )
{
qDebug() << m_pTableModel->lastError().text();
qDebug() << m_pTableModel->query().lastQuery();
}

I did that, but since operation is sucessfull, qDebug statements are skipped.

jacek
8th January 2006, 16:23
I did that, but since operation is sucessfull, qDebug statements are skipped.
How about this?
m_pTableModel->insertRecord( INSERT_RECORD_AT_END, cDataRecord );
if( m_pTableModel->submitAll() )
{
qDebug() << "Data submitted successfully";
}
else {
qDebug() << m_pTableModel->lastError().text();
qDebug() << m_pTableModel->query().lastQuery();
}

MarkoSan
8th January 2006, 18:22
So, am I nut or what? This time submitAll failed and first qDebug() we have


QSqlQueryModel::lastError returned {...}
QSqlError::text returned {" " size=1}

and after second qDebug() we have:


QSqlQueryModel::query returned {...}
QSqlQuery::lastQuery returned {"SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.I ME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_k raja FROM stranka,u" size=217}


What is going on?

jacek
8th January 2006, 18:53
What is going on?
Indeed something strange is going on. What does QSqlError::type() return?

MarkoSan
8th January 2006, 18:57
Ok, this is diagnostic code:


if(m_pTableModel->submitAll())
{
qDebug() << "Data submitted successfully";
} else
{
qDebug() << m_pTableModel->lastError().text();
qDebug() << m_pTableModel->lastError().type();
qDebug() << m_pTableModel->query().lastQuery();
}


This is very very strange:


QSqlError::type returned NoError


NoError has been reported!!! How come???

wysota
8th January 2006, 18:58
SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.I ME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_k raja FROM stranka,u

This stinks... What is the table "kraj" doing here if it's not in the "FROM" part of the query? On the other hand, looks like "u" is not used here, so why is it in the statement? Is that a complete output from lastQuery? Is this a SqlTableModel or QSqlRelationalTableModel? How come SqlTableModel has more than one table in use? Is that last query connected with the model at all?

MarkoSan
8th January 2006, 19:03
This stinks... What is the table "kraj" doing here if it's not in the "FROM" part of the query? On the other hand, looks like "u" is not used here, so why is it in the statement? Is that a complete output from lastQuery? Is this a SqlTableModel or QSqlRelationalTableModel? How come SqlTableModel has more than one table in use? Is that last query connected with the model at all?
You are right. Does submitAll() generated any SQL statement? The reason I ask is that that statement is responsible for displaying data in QSqlRelationalTableModel and it works fine and lastQuery after sumbitAll still reports that statement, which is obviously not statement for inserting records.

The statement that I get from debuger is:


QSqlQuery::lastQuery returned {"SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.I ME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_k raja FROM stranka,u" size=217}

wysota
8th January 2006, 19:14
Do you have access to that MySQL's query log? Could you check last queries which are executed before getting that wrong behaviour?

MarkoSan
9th January 2006, 09:02
Here is log file listing:


D:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt, Version: 5.0.16-nt-log. started with:
TCP Port: 3306, Named Pipe: (null)
Time Id Command Argument
060108 22:42:59 1 Connect root@localhost on possystem
1 Init DB possystem
1 Field List stranka
1 Field List stranka
1 Field List stranka
1 Query show index from stranka
1 Field List stranka
1 Query SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.I ME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_k raja FROM stranka,ulica,kraj WHERE (stranka.ULICA=ulica.ulica and stranka.POSTA_STEVILKA=kraj.postna_stevilka)
D:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt, Version: 5.0.16-nt-log. started with:
TCP Port: 3306, Named Pipe: (null)
Time Id Command Argument
060109 8:53:59 1 Connect root@localhost on
1 Query SET SESSION interactive_timeout=1000000
1 Query SELECT @@sql_mode
1 Query SET SESSION sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION'
1 Query SET NAMES utf8
2 Connect root@localhost on
2 Query SET SESSION interactive_timeout=1000000
2 Query SELECT @@sql_mode
2 Query SET SESSION sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER, NO_ENGINE_SUBSTITUTION'
2 Query SET NAMES utf8
2 Quit
060109 8:59:48 3 Connect root@localhost on possystem
3 Init DB possystem
3 Field List stranka
3 Field List stranka
3 Field List stranka
3 Query show index from stranka
3 Field List stranka
3 Query SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.I ME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_k raja FROM stranka,ulica,kraj WHERE (stranka.ULICA=ulica.ulica and stranka.POSTA_STEVILKA=kraj.postna_stevilka)
060109 8:59:56 3 Quit
060109 9:00:08 1 Query SHOW VARIABLES LIKE 'datadir'
1 Query SHOW VARIABLES LIKE 'log_error'

I do not see INSERT statement anywhere!!

MarkoSan
10th January 2006, 07:53
Please help!!!

wysota
10th January 2006, 11:20
Does insertRecord() return true?

MarkoSan
10th January 2006, 11:24
Yes, I've tried it several times. submitAll also returns true, there is no visible error (in debugger), just empy field is added to QSqlRelationDataModel (not to databse, becasue if I reopen window, the empty field dissapears). I thought it was something wrong with relations, so I commented relation setup, still same result. Do you need whole code listing?

wysota
10th January 2006, 11:25
Try this:


QSqlRecord rec;
rec.append(QSqlField("id", QVariant::Int));
rec.append(QSqlField("name", QVariant::String));
rec.append(QSqlField("address", QVariant::String));
rec.setValue("id", lineedit1->text());
rec.setValue("name", lineedit2->text());
rec.setValue("address", lineedit3->text());
//...
model->insertRecord(-1, rec);

MarkoSan
10th January 2006, 11:43
God damn, it works, but still there is no data in the table after reopening the window! Is this problem maybe connected with my databse schematic, because I have an ID field in customer table autonumbered, but I cannot get its value from SQL to Qt?

jacek
10th January 2006, 11:45
Try this:


QSqlRecord rec;
rec.append(QSqlField("id", QVariant::Int));
rec.append(QSqlField("name", QVariant::String));
rec.append(QSqlField("address", QVariant::String));
I just wonder why didn't we thought about this earlier :confused:

A shorter version:
QSqlRecord rec( m_pTableModel->record() );

MarkoSan
10th January 2006, 11:54
I just wonder why didn't we thought about this earlier :confused:

A shorter version:
QSqlRecord rec( m_pTableModel->record() );

But isn't there a QSqlDatabase connection or some other mechanism, which fetches fields names automaticly?

MarkoSan
10th January 2006, 12:07
But isn't there a QSqlDatabase connection or some other mechanism, which fetches fields names automaticly?

Now it works, thank you very very much! But can you please tell me how to fetch ID of CUSTOMER, which is set to AUTONUMBER in SQL Administrator, but it does not work, since If I add record manualy, the ID does not grow!!

jacek
10th January 2006, 12:15
But isn't there a QSqlDatabase connection or some other mechanism, which fetches fields names automaticly?
That's what QSqlTableModel::record() does.


can you please tell me how to fetch ID of CUSTOMER, which is set to AUTONUMBER in SQL Administrator, but it does not work, since If I add record manualy, the ID does not grow!!
Try:
rec.setGenerated( "id", false );

MarkoSan
10th January 2006, 12:43
Ok, I have another question: Why do I get now table filled with new data correctly, but If i reopen windows, the data dissapears, that means, record is still not being written to database?

jacek
10th January 2006, 12:52
Did you try QSqlTableModel::submit() or QSqlTableModel::submitAll()?

MarkoSan
10th January 2006, 13:21
I checked it out, just wait, now returns false, I'll post the error soon.

MarkoSan
10th January 2006, 13:34
I checked it out, just wait, now returns false, I'll post the error soon.

submitAll returns false, further diagnostic:


QSqlError::type returned StatementError
QSqlQueryModel::query returned {...}
QSqlQuery::lastQuery returned {"SELECT stranka.SIFRA,stranka.DS,stranka.PRIIMEK,stranka.I ME,ulica.naziv,stranka.STEVILKA_ULICE,kraj.naziv_k raja FROM stranka,u" size=217}

wysota
10th January 2006, 14:17
I just wonder why didn't we thought about this earlier :confused:


Because we didn't read QSqlRecord docs carefully enough (I didn't read it at all, just looked at it).

fane
10th January 2006, 15:55
I have been watching this thread since its beginnings because I am stuck with the same problem. Look at this scenario:
Two database tables

CUSTOMERS
customer_id INTEGER AUTOINCREMENT NOT NULL
name VARCHAR
city INTEGER NOT NULL DEFAULT 0

CITIES
city_id INTEGER AUTOINCREMENT NOT NULL
city_name VARCHAR

A model:

model = new QSqlRelationalTableModel(this);
model->setTable("customers");
model->setRelation(2, QSqlRelation("cities", "city_id", "city_name"));
model->select();


"this" beeing the form on which there is a QTableView:


ui.tableView->setModel(model);


A QPushButton insertButton and a custom slot:



void MainWindow::on_insertButton_clicked(bool checked)
{
QSqlRecord rec = model->record();

rec.setValue("name", "Test Customer");
rec.setValue("city_name", "London");

bool insert = model->insertRecord(-1, rec);
bool submit = model->submit();
}


The select statement upon which the model is created is like this:
"SELECT customers.customer_id, customers.name, cities.city_name
FROM customers, cities
WHERE customers.city = cities.city_id"
This is the return of model->query().lastQuery().

The QSqlRecord rec from above have the same fields: customer_id, name, city_name, which is obvious.
BUT if you run the code like this both insertRecord() and submit() return FALSE and the last error reported by model->lastError().text() is:
"Unknown column 'city_name' in 'field list' QMYSQL3 : QMYSQLResult". Surprisingly in the tableView there is a new row which contain the values used by the setRecord() calls.
You get the same result if you use a numerical value with rec.setValue() in line 6:


rec.setValue("city_name", 1);


QSqlTableModel::insertRecord() calls internally QSqlTableModel::insertRows() and QSqlTableModel::setRecord(). The new row is shown in the tableView and that means that only insertRows() worked but not setRecord().

Now change this line (6) to be like this:

rec.setValue("city", 1);
Both insertRecord() and submit() return TRUE, the record is added in the database (I have checked with MySQL Query Browser) but the field "city" is set to 0, which is the default value for the field and model->lastError().text() is empty. The record isn't shown in the tableView because there is no corresponding record in the related table "cities" to match the WHERE clause 'customers.city = cities.city_id'.

So the first way is not good (it generates SQL errors and no record added) the second one seems also not to be working (no SQL error, record added, but with a useless value in the field upon the relation is set). Until now I couldn't narrow it more than this. Which way??

wysota
10th January 2006, 17:35
The behaviour is (probably) because you can't insert into two tables with a single insert statement. Using this model you can only insert into the table which you set to be the model table ("customers" in your case). That's why you have to reference "city" and not "city_name".

Now we come to the second part -- the Problem(R).

I would try two things:

1.
rec.setValue("city", "London");
2.
rec.setGenerated("city", true);

A third thing to do could be to check what is the type of QVariant associated with "city" field (using rec.field().type()).

wysota
10th January 2006, 17:38
Ok, I have another question: Why do I get now table filled with new data correctly, but If i reopen windows, the data dissapears, that means, record is still not being written to database?

Is it not written to the database or not displayed in the tableview?


Oh, and guys, try not to use UPPERCASE column names in SQL tables, it's a risk while porting between platforms.

fane
10th January 2006, 19:01
Thanks.
1. I have tried
rec.setValue("city", "London"); and
rec.setValue("city", 1) ; with the same result -- record added to database but 'city' field value == 0.

2 - 3. I'll go for them later, I do not have Qt4 right now.

Is my problem similar to MarkoSan's or am I wrong?

fane
11th January 2006, 18:30
I have done some more "research" and this is what I have:
rec.field("city").type() returns QVariant::Invalid - that's because rec does not contain a field named "city".
rec.field("city_name").type() returns QVariant::String which is correct as long the database field city_name is a VARCHAR.

Using rec.setValue("city", "London") apparently works because QSqlRecord::setValue(const QString & name, const QVariant & val) does nothing if the field ("city" in this case) does not exist. So the record is inserted in the database using the default value (0) for the field "city_name" which is contained by the record rec. In this case why rec.setValue("city_name", "London") doesn't work and model->insertRecord(-1, rec) returns FALSE?
I have also found something that looks strange, at least for me. I run in MySQL QueryBrowser the query upon which the QSqlRelationalTableModel model is filled with data and a saw that I can't insert or update records in the resultset returned.

I think I have to dig deeper into this model/view architecture. For now I will try a different approach and use a QSqlQuery("INSERT INTO ...") to make things going on, but the topic still remains opened.

wysota
11th January 2006, 18:35
You might want to ask Trolltech about it, it might be some kind of bug or lack of documentation.

MarkoSan
12th January 2006, 12:58
I know why submitAll is not working for me. I've set up foreign keys, but I had not done the JOIN statement, I'll try it now and report the result.

GreyGeek
13th January 2006, 17:48
I do something like what is shown below, but if you have an updatable view (using multiple tables) on your database then something similar to this snippet should work.


void homestead::UpdateProperty() {
QDateTime dtNow = QDateTime::currentDateTime();
QString propQryPrep = "UPDATE property_";
propQryPrep.append(this->dbYear);
propQryPrep.append(" SET \
county = :county, \
cntyname = :cntyname, \
txdistrict = :txdistrict, \
legal = :legal, \
parcel_id = :parcel_id, \
pvalue = :pvalue, \
entry_id = :entry_id, \
entry_date = :entry_date, \
notes = :notes \
WHERE proprty_id = :proprty_id");

propQry.prepare(propQryPrep);
propQry.bindValue(":county",ui.leCountyNumber->text().toInt());
propQry.bindValue(":cntyname",ui.cboCountyName->currentText());
propQry.bindValue(":txdistrict",ui.leTaxDistrict->text());
propQry.bindValue(":legal",ui.txtLegal->toPlainText());
propQry.bindValue(":parcel_id",ui.leParcelID->text());
propQry.bindValue(":pvalue",ui.leHomeValue->text().toInt());
propQry.bindValue(":entry_id",homestead::RevID);
propQry.bindValue(":entry_date",dtNow);
propQry.bindValue(":notes",ui.teNotes->toPlainText());
propQry.bindValue(":proprty_id",ui.leProprtyID->text().toInt());
if (propQry.exec()) {
ui.leStatus->setText("Property record: "+ui.leProprtyID->text()+" updated!");
} else {
ui.leStatus->setText("Cannot updated property record: "+ui.leProprtyID->text());
}
}

BTW, this code works on Oracle and on PostgreSQL before 8.1.0. On PostgreSQL after 8.0 they've added 3 millisecond positions to the QDateTime return.

fane
13th January 2006, 18:39
I have found a solution to my problem. I have appended a QSqlField to the record retrieved with model->record()


QSqlRecord rec = model->record();
QSqlField cityField("city", QVariant::Int);
rec.append(cityField);
rec.setValue("name", "Test Customer");
rec.setValue("city", 1); // or whatever value exists in the related table 'cities'

model->insertRecord(-1, rec);
model->submit();

'city' is the name of a field in the 'customers' database table but which is not part of the query that filled the model.
'city_name' is the name of a field in the related table 'cities' and is contained by rec.
I run this code and I got the same "error" - record inserted in the table 'customers' but the value of 'city' field is set to the default == 0. Then I have installed Qt 4.1.0 and magically it worked - record inserted with proper value for field 'city' == 1 (in this case).
So, as wysota said, it is probably a bug in Qt 4.0.0.
Thanks for all suggestions.

MarkoSan
17th January 2006, 15:35
Whatever I do, I cannot get data into database!!!! I am going mad!!!

wysota
17th January 2006, 15:46
Whatever I do, I cannot get data into database!!!! I am going mad!!!

Please provide a minimal compilable example which reproduces the problem. Your code is too complex (and incomplete) for us to test on our own machines.

MarkoSan
18th January 2006, 12:01
Please provide a minimal compilable example which reproduces the problem. Your code is too complex (and incomplete) for us to test on our own machines.

I tried, but zip file is too big and i do not know how to distribure sql databse.

MarkoSan
18th January 2006, 12:44
Is the situation maybe connected with http://www.trolltech.com/developer/tasktracker.html?method=entry&id=86645, what do you think?

wysota
18th January 2006, 13:08
I tried, but zip file is too big and i do not know how to distribure sql databse.

So make it smaller. The example is to be minimal. We don't need your database, just a table schema and some sample data.

MarkoSan
18th January 2006, 13:23
Here is minimal project file and sources (VC++ 6.0 Service Pack 6, Qt 4.0.1). After unziping in .sql file there are table declarations and sample data.

fane
18th January 2006, 19:50
I have managed to make it work but I use Qt 4.1.0 on WinXp and MySQL 4.1.11. Similar code didn't work on Qt 4.0.0, but I don't know about 4.0.1. My modifications are commented with 'modified by fane' (hope I didn't miss anyone), and of course your MySQL root password has to be changed.
I have appended two QSqlFields to the record retrieved with model->record() named "ULICA" and "POSTA_STEVILKA", set their value with QSqlRecord::setValue(). I have modified the edit strategy to be OnRowChange and removed the setValue() call for the "SIFRA" field which is autoincremented by MySQL.
I guess you have to move to Qt 4.1.0 according to this (http://www.trolltech.com/developer/tasktracker.html?method=entry&id=86645)