Best way to make Db calls - Qt



  • Hi,

    In my app, I have to make a lot of db calls while the app is running. I am making all of those calls on the main thread. The application ui freezes frequently. I suspect the db calls that I am making for this.

    Do you think making Db calls on main thread is a good approach? Shall I move them to a separate thread?
    If so, can you please suggest a better way? I have been using threads in the app as well but I am creating separate classes for this which derive from @QThread @class. Is there a way in which I could execute a time-expensive operation in a separate block which will run in a separate thread something like the way it happens in java?

    I want a solution in which I will not have to create a separate thread class to do a task. Please suggest.

    Thanks



  • There is no way but use a separate thread.
    Also in Java you have to create a separate thread. So, I don't know what are you refer to when you say "the way it happens in java?".

    Anyway, Qt offers solutions to avoid to explicit create a subclass of QThread. And the solution is the Qt Concurrent module: http://qt-project.org/doc/qt-5.1/qtconcurrent/qtconcurrent-index.html

    With Concurrent module you can "submit" some function to run concurrently with the main thread with the possibility to realize also parallel algorithms (if you want).



  • thanks that was helpful


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.