[Qt-interest] Showing a "Please wait" dialog during sql query
Gillen Daniel
gillen.daniel at gmail.com
Mon Jun 7 20:27:23 CEST 2010
On 06/07/2010 07:47 PM, Scott Aron Bloom wrote:
> Ive had the same problem. I have worked on it, but no "real" success
> yet..
>
> Mine is a bit harder, because my SQL query is being used in a SQL Model,
> not just a dialog.
>
> But here is what I am trying.. And in speaking with some trolls, should
> work if I ever get the full time to devote to it.
>
> Assign the QSqlQuery and QSqlDatabase in a thread dedicated to the
> display class. In my case a QSqlModel your case is QDialog derived
> class.
>
> Show the dialog, have it start the thread. Have the threads run emit a
> signal when its finished, and exit the thread, but do not delete the
> thread.
>
> Use the data from the QSql data from the thread. Once you are finished
> retrieving the data, you can delete the thread/QSql data.
>
> The display should stay valid during the exec.
>
> Scott
>
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com
> [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Gillen Daniel
> Sent: Monday, June 07, 2010 10:32 AM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] Showing a "Please wait" dialog during sql query
>
> Hi @all
>
> I have a massive problem here and don't seem to find a solution for it.
>
> I'm developping a database application based on a MySQL database and I
> would need to display a "Please wait" dialog while
> populating a QSqlQueryModel. The data from QSqlQueryModel gets displayed
>
> in a widget in my main window, so I have to exec the query in my main
> thread. The problem is that any dialog I open before querying the data
> hangs as my query blocks the main thread.
>
> Does anyone has an idea on how I could solve this? I would need some
> sort of 2nd thread which displays the dialog with his own event loop but
>
> as far as I understand, Qt does not support GUI interaction in a second
> thread. Or is it perhaps possible to exec the query in a second thread
> and then move the whole QSqlQueryModel and database connection to my
> main thread?
>
> Thx in advance
>
>
As far as I can see it's exactly the same as mine as I also need the
data in a model that gets displayed in my main window.
The dialog should only inform the user that a query is beeing executed
and the program hasn't crashed.
So just to clarify this, in my MainWindow I start a thread which opens a
database connection, executes my SQL query, emits a signal to my
MainWindow and exits. The slot receiving this signal uses the QSqlQuery
from the thread and assigns it to my QSqlModel which is then assigned
for ex. to a QTableModel widget?
Sorry but this seems a bit confusing to me or didn't I get it right?
--
Unix _IS_ user friendly - it's just
selective about who its friends are!
More information about the Qt-interest-old
mailing list