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. Update Data to mongodb through Qthread..
QtWS25 Last Chance

Update Data to mongodb through Qthread..

Scheduled Pinned Locked Moved Solved General and Desktop
qthread threadsqthreadqt5.11qtcreator 5.0multithreading
6 Posts 3 Posters 871 Views
  • 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.
  • Vivek_AV Offline
    Vivek_AV Offline
    Vivek_A
    wrote on last edited by
    #1

    Iam trying to send data to mongodb (Mongocxx) through qthread because its freeze main GUI while data inserting to db .
    I implemented a sample below , but still have the gui freeze . i think something missing in threading .. please look at the code and help please .

    in RTLSClient.cpp

    onethread = new myThread(this);
    connect(this,&RTLSClient::sendtodb,onethread,&myThread::recvNum);
    onethread->start();
    }
    void RTLSClient::newData()
    {
       while(this->socket->bytesAvailable())
         {
           qint64 dataLen = this->socket->peek(data, sizeof(data));
           emit sendtodb(2.0,3.0);
         }
    }
    myThread::myThread(QObject *parent)
       : QThread(parent)
    {
    }
    
    void myThread::recvNum(double x,double y)
    {
    //   this->m1=x;
    //   this->m2=y;
       std::vector<bsoncxx::document::value> documents;
       documents.push_back(
       bsoncxx::builder::stream::document{} <<"bool"<<1 <<"POSX"<<x<<"POSY"<<y<<finalize);
       db["xxx"].insert_many(documents);
       qDebug()<<"threadLast";
    }
    
       ``
    DATA getting db but GUI freeze when more data coming ....

    vk

    JonBJ Christian EhrlicherC 2 Replies Last reply
    0
    • Christian EhrlicherC Christian Ehrlicher

      @Vivek_A said in Update Data to mongodb through Qthread..:

      connect(this,&RTLSClient::sendtodb,onethread,&myThread::recvNum);

      Please take a look into the QThread documentation on why this slot is executed in the main thread. QThread is not a thread, it's a class which controls a thread!

      Vivek_AV Offline
      Vivek_AV Offline
      Vivek_A
      wrote on last edited by
      #6

      @Christian-Ehrlicher @JonB Solved . By creating a seperate worker.cpp file and connected RTLSClient signal to worker slot, now data is inserting to mongodb very fast without freezing GUI.
      Thanks ..

      vk

      1 Reply Last reply
      0
      • Vivek_AV Vivek_A

        Iam trying to send data to mongodb (Mongocxx) through qthread because its freeze main GUI while data inserting to db .
        I implemented a sample below , but still have the gui freeze . i think something missing in threading .. please look at the code and help please .

        in RTLSClient.cpp

        onethread = new myThread(this);
        connect(this,&RTLSClient::sendtodb,onethread,&myThread::recvNum);
        onethread->start();
        }
        void RTLSClient::newData()
        {
           while(this->socket->bytesAvailable())
             {
               qint64 dataLen = this->socket->peek(data, sizeof(data));
               emit sendtodb(2.0,3.0);
             }
        }
        myThread::myThread(QObject *parent)
           : QThread(parent)
        {
        }
        
        void myThread::recvNum(double x,double y)
        {
        //   this->m1=x;
        //   this->m2=y;
           std::vector<bsoncxx::document::value> documents;
           documents.push_back(
           bsoncxx::builder::stream::document{} <<"bool"<<1 <<"POSX"<<x<<"POSY"<<y<<finalize);
           db["xxx"].insert_many(documents);
           qDebug()<<"threadLast";
        }
        
           ``
        DATA getting db but GUI freeze when more data coming ....
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #2

        @Vivek_A
        Put qDebug() statements at the beginning, end and in the middle of RTLSClient::newData(). I don't know how you think that is going to function.

        Not to mention, you don't actually show any call to it, your code doesn't show much of what must actually be going on elsewhere in it.

        Vivek_AV 1 Reply Last reply
        0
        • JonBJ JonB

          @Vivek_A
          Put qDebug() statements at the beginning, end and in the middle of RTLSClient::newData(). I don't know how you think that is going to function.

          Not to mention, you don't actually show any call to it, your code doesn't show much of what must actually be going on elsewhere in it.

          Vivek_AV Offline
          Vivek_AV Offline
          Vivek_A
          wrote on last edited by
          #3

          @JonB The source code very lengthy ... one thing i can say .. in that RTLSClient.cpp there is lot of emit signals given for GraphicsWidget gui update . and from socket takinng data and update to gui and trying to send to db .. this is the logic .
          And i posted the same in mongocxx forum , no reply yet ,
          same scenario like this updating db through QThread except the code ..

          vk

          JonBJ 1 Reply Last reply
          0
          • Vivek_AV Vivek_A

            @JonB The source code very lengthy ... one thing i can say .. in that RTLSClient.cpp there is lot of emit signals given for GraphicsWidget gui update . and from socket takinng data and update to gui and trying to send to db .. this is the logic .
            And i posted the same in mongocxx forum , no reply yet ,
            same scenario like this updating db through QThread except the code ..

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #4

            @Vivek_A
            I suggested you put 3 qDebug() statements into your RTLSClient::newData(), before loop, in loop, after loop, to see what is going on. I do not see why you think that loop will ever exit. Up to you.

            1 Reply Last reply
            0
            • Vivek_AV Vivek_A

              Iam trying to send data to mongodb (Mongocxx) through qthread because its freeze main GUI while data inserting to db .
              I implemented a sample below , but still have the gui freeze . i think something missing in threading .. please look at the code and help please .

              in RTLSClient.cpp

              onethread = new myThread(this);
              connect(this,&RTLSClient::sendtodb,onethread,&myThread::recvNum);
              onethread->start();
              }
              void RTLSClient::newData()
              {
                 while(this->socket->bytesAvailable())
                   {
                     qint64 dataLen = this->socket->peek(data, sizeof(data));
                     emit sendtodb(2.0,3.0);
                   }
              }
              myThread::myThread(QObject *parent)
                 : QThread(parent)
              {
              }
              
              void myThread::recvNum(double x,double y)
              {
              //   this->m1=x;
              //   this->m2=y;
                 std::vector<bsoncxx::document::value> documents;
                 documents.push_back(
                 bsoncxx::builder::stream::document{} <<"bool"<<1 <<"POSX"<<x<<"POSY"<<y<<finalize);
                 db["xxx"].insert_many(documents);
                 qDebug()<<"threadLast";
              }
              
                 ``
              DATA getting db but GUI freeze when more data coming ....
              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #5

              @Vivek_A said in Update Data to mongodb through Qthread..:

              connect(this,&RTLSClient::sendtodb,onethread,&myThread::recvNum);

              Please take a look into the QThread documentation on why this slot is executed in the main thread. QThread is not a thread, it's a class which controls a thread!

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              Vivek_AV 1 Reply Last reply
              2
              • Christian EhrlicherC Christian Ehrlicher

                @Vivek_A said in Update Data to mongodb through Qthread..:

                connect(this,&RTLSClient::sendtodb,onethread,&myThread::recvNum);

                Please take a look into the QThread documentation on why this slot is executed in the main thread. QThread is not a thread, it's a class which controls a thread!

                Vivek_AV Offline
                Vivek_AV Offline
                Vivek_A
                wrote on last edited by
                #6

                @Christian-Ehrlicher @JonB Solved . By creating a seperate worker.cpp file and connected RTLSClient signal to worker slot, now data is inserting to mongodb very fast without freezing GUI.
                Thanks ..

                vk

                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