I think part of your problem may be the query getting emitted.
If its crossing a thread boundary on your signal->slot connection, and is being
queued, then it's being copied.
And the data from the db will not be copied with it.
That's why in the example I posted, the other thread (the model) gets direct
access to the QSqlQuery, and the thread is ONLY used to do the exec
Note, I have extended my example (not posted) to allow for multiple queries, if
you want I can post up an example showing that.
From: Linos [mailto:info@xxxxxxxx]
Sent: Tuesday, June 08, 2010 8:59 AM
To: Scott Aron Bloom
Cc: Andre Somers; Qt-Interest
Subject: Re: [Qt-interest] Showing a "Please wait" dialog during sql query
i am creating the connection to the database and the query inside the thread,
more specifically i create an QObject subclass that i call Worker in the
run method and in Worker i create the database connection, in every call for
execute a query the Worker class create a new query with his database
and execute the query, when the query has finished i emit the QSqlQuery from
Worker to the QThread subclass and from the QThread subclass to the main gui
where i assign it to a QSqlQueryModel.
This shows the behavior described in the last email, the first query works
wonderfully, the second query breaks the first model and show the results of
last query. I can attach the python module i use for this if any want to see, i
have had not time to try other options but i would like to avoid have to make
special model to work with the record of every row or the variant of every
column for every row.
El 08/06/10 17:25, Scott Aron Bloom escribió:
> The problem is, the ownership and affinety of the QSqlQuery must be the same
> as the QSqlDatabase (This from Bill King of Nokia who is the/one of Nokia's
> Qt database guys)
> So what I got working, is creating the QSqlDatabase and its connection
> inside the thread (during the run phase), running the exec and emitting a
> signal when finished.
> Once its finished, then you can use the QSqlQuery from the other thread
> Note, I have NOT tried modifying the QSqlQueyrModel, I would expect that if
> you got the QSqlRecord from the thread it would be ok..
> On 6/8/10 1:16 AM, "Linos" <info@xxxxxxxx> wrote:
> > I am using something like this with pyqt, the only difference it is
> that i
> > emit
> > the QSqlQuery in a signal when the query has finished instead of
> return it
> > from
> > a method, but when later i execute other query in the same sql
> QThread with a
> > new created QSqlQuery in the same QSqlDatabase connection of the
> thread, the
> > first model get corrupted and gets the values of the last query.
> > Miguel Angel
> > El 08/06/10 07:53, Scott Bloom escribió:
> >> It got stripped.. My sent items has it attached...
> >> It was/is a zip file...
> >> Scott
> >> On 6/7/10 10:23 PM, "Andre Somers"<andre@xxxxxxxxxxxxxxxx> wrote:
> >>> Op 8-6-2010 0:22, Scott Aron Bloom schreef:
> >>>> I have attached a working solution. Its not fully vetted, so bugs
> >>>> probably exist :) but it works in the case shown...
> >>> Unfortunately, you have attached nothing...
> >>> André
> >>> _______________________________________________
> >>> Qt-interest mailing list
> >>> Qt-interest@xxxxxxxxxxxxx
> >>> http://lists.trolltech.com/mailman/listinfo/qt-interest
> >> _______________________________________________
> >> Qt-interest mailing list
> >> Qt-interest@xxxxxxxxxxxxx
> >> http://lists.trolltech.com/mailman/listinfo/qt-interest
Qt-interest mailing list