Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Database stuff in another thread class?
R_Irudezu last edited by
I am doing graphic stuff and sql queries in same (UI thread). My sql queries are need to be done every moment as quick as possible. So i am using a timer like that:
QTimer *blobLoaderTimer = new QTimer(this); connect(blobLoaderTimer , SIGNAL(timeout()), this, SLOT(load_blobs_to_qLabels())); blobLoaderTimer ->start(); blobLoaderTimer ->setInterval(50); // or zero
At the same time i am creating many graphicsScenes and views but it is too delayed. When i comment sql timer lines, graphic drawing stuff accelerates.
The question is, if i move the sql stuff to another thread with subclassing QThread class is it gonna be a good move? I need your suggestions. Thanks in advance.
I'm not to versed with Databases, so I won't comment on that.
But, before you go and subclass QThread, read through this:
Since you want to use signals and slots, there's no need to subclass QThread. Use the worker object approach.
What exactly do you want to do with that database ?
R_Irudezu last edited by R_Irudezu
@SGaist checking a directory all the time (as quick as possible) then if a new file is in the directory -> get that file and upload to db, at the same time, show the last 10 files in the UI. I'm doing the second one in every 1 or 2 seconds. But the first job must be speed.
Use QFileSystemWatcher to check the modifications to directory. Then push the data to DB. You can use threading for this task. Now do you have any issue here ?
Threading with databases is finicky - there are limitations - avoid it if you can.