PDA

View Full Version : Threaded QSql + QT MVC mechanism



grzesiek
29th July 2011, 12:19
Hello,

I have small problem regarding QT's MVC mechanism.

I managed to create some code that allows me to use threaded MySQL queries with QT (database engine class + threaded worker class exchanging lists of QSqlResult objects). This works fine for me.

But know I'm looking for best way of connecting threaded sql with QT's MVC mechanism (for example with QSqlRelationalTableModel class).

I'm currently working with application using SQL in single thread with relational table model (MVC way), but database has grown larger and this way is no longer acceptable.

I have few classes that are derived from QSqlRelationalTableModel and I'm using in application. I suppose it is the place I should start reimplementation - maybe something like - QSqlRelationalTableModel using QSqlResult list from my threaded database engine. This mean - db engine <-(QList<QSqlResult>)-> db worker, and QSqlTableModel reimplementation. Is that correct method ?

Maybe some one has done it before ?

I was looking for some hint all over the internet for months - so far no luck.

Thanks in advance for help & hints !

Best Regards,
Grzesiek

miraks
29th July 2011, 12:43
Hi,

Take care, as you can see here: http://doc.qt.nokia.com/4.7-snapshot/threads-modules.html (http://doc.qt.nokia.com/4.7-snapshot/threads-modules.html)
"A connection can only be used from within the thread that created it. Moving connections between threads or creating queries from a different thread is not supported."

grzesiek
29th July 2011, 13:16
Take care, as you can see here: http://doc.qt.nokia.com/4.7-snapshot/threads-modules.html (http://doc.qt.nokia.com/4.7-snapshot/threads-modules.html)
"A connection can only be used from within the thread that created it. Moving connections between threads or creating queries from a different thread is not supported."

Yes, that is right, but who said I'm moving SQL connection between threads ?

I'm creating and using SQL connection in separate thread and only moving QList<QSqlResult> between threads - and that is OK and is WORKING. There is no limitation in moving QSqlResult objects between threads.

The thing is - how to integrate this with QT's MVC mechanism.

Regards,
Grzesiek