Clone the database connection, open it, run your query, close and remove the connection. Everything apart cloning has to be done from the thread that is to execute the query.
Clone the database connection, open it, run your query, close and remove the connection. Everything apart cloning has to be done from the thread that is to execute the query.
If you want to use signal/slots to communicate from the GUI to the worker thread then you'll need a QThread that runs an event loop.
You start by creating a QObject subclass that has the receiver slot and that slot does the database query.
You create an instance of QThread and an instance of this new class and then use moveToThread() to make it run in the worker thread.
The slot then gets invoked in the context of the worker thread.
Cheers
_
Thanks for the reply
my problem is that , i have a class the represents the GUI , a button in it, when pressed it opens a dialog
now in this dialog i get the user input through line edit , and i have a button , when pressed i want to execute the query
so should i connect to the database in the main GUI ? or in the class subcalssing QObject ?
the other problem is that if i start the thread on pressing the button in the dialog , the thread will get destroyed before doing the query
where to create the intsnance of the class subclassing QObject ?
since my query takes parameters , i should pass them to the Thread. How to do that ? Signals and Slots are not doing the job properly in my case
I would do it in the qobject class, in the slot that executes the query or in a slot connected to the thread's started signal.
Why would it? The default implementation of QThread::run() runs an event loop. it doesn't finish until QThread::exit() is called.
When you create the thread. Since you want to directly connect the dialog to the query slot, before you create the dialog or even when you create the applicatIons' main GUI.
Signals can transport parameters to the slot.
Does it work if you do not use a thread and have the query class instance in the main thread?
Cheers,
_
Bookmarks