PDA

View Full Version : Protect QSqlQueryModel in two threads



john_crichton
2nd May 2008, 12:24
Hello, I am currently working on a database application that has two threads - the query thread and the gui thread. The data is sent from query thread to gui thread in form of QSqlQueryModel*. Everything works fine and the application is operational but still I would like to have my QSqlQueryModel *model protected so that only one thread at a time can use it. In the gui thread I have the following piece of code:

ui.tableView->setModel(model);
ui.tableView->setColumnWidth(0, 50);
ui.tableView->setColumnWidth(1, 250);
ui.tableView->setColumnWidth(2, 250);
ui.tableView->setColumnWidth(3, 100);
ui.tableView->show();
In the query thread I have the following code:

model->setQuery(*query);
How could I achieve the following: When one piece of code starts the other would not get executed until the first one has finished.
Thanks in advance for any help you offer.

john_crichton
2nd May 2008, 17:00
I have finished a small test application in Qt 4.3. For now it is a small database with gui to add and delete items and search the database. The application shows the use of QSettings, some use of SQL module and the basic multithreading. It is not finished as I yet don't have the answers to the question from the previous post. Anyway if anyone wants the code of this application feel free to contact me and I'll send it to you. Best regards john_crichton.