Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Database stuff in another thread class?

Database stuff in another thread class?

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 5 Posters 730 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R_IrudezuR Offline
    R_IrudezuR Offline
    R_Irudezu
    wrote on last edited by
    #1

    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.

    Keizoku wa chikaranari.

    J.HilkJ 1 Reply Last reply
    0
    • R_IrudezuR R_Irudezu

      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.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @R_Irudezu
      I'm not to versed with Databases, so I won't comment on that.

      But, before you go and subclass QThread, read through this:

      https://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        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 ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        R_IrudezuR 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          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_IrudezuR Offline
          R_IrudezuR Offline
          R_Irudezu
          wrote on last edited by R_Irudezu
          #4

          @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.

          Keizoku wa chikaranari.

          kshegunovK 1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            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 ?

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            1 Reply Last reply
            0
            • R_IrudezuR 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.

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              Threading with databases is finicky - there are limitations - avoid it if you can.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved