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. QTChart draws line from first to last point
Forum Updated to NodeBB v4.3 + New Features

QTChart draws line from first to last point

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 427 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.
  • J Offline
    J Offline
    jawad_soft
    wrote on last edited by
    #1

    Hi i'm using QT chart to draw Real Time series with data coming from variable "new_vibe" wich it's refreshed all time.
    My serie are composed of 15 points, to refresh ma serie, i append to each point the value of the point +1 and i append "new_vibe" to the point 15.

    There is the code of my thread :

    while(1)
    {
               new_vibe = new_data(); //function that refresh data
    
               series->clear();
    
               for(int j=0; j <= 15; j++)
                   {
    
                        if(j == 15)
                            {
                                graph[j] =  VIBRATION;
                            }
                        else
                            {
                                graph[j] = graph[j+1];
                            }
    
                        series->append(QPointF(j, graph[j]));
    
                   }
    
                 chart->update();
    
                 QThread::msleep(500);
            }
    
    the refresh process work fine and i check that data are correct, but draws line from , you can see below, i try to append in the order 15 -> 0 but nothing change ! can some one help me ? thanks.
    
    ![ll.png](https://ddgobkiprc33d.cloudfront.net/dabb007e-f54b-43c8-8d80-501c4795b429.png) 
    
    
    KroMignonK 1 Reply Last reply
    0
    • J jawad_soft

      Hi i'm using QT chart to draw Real Time series with data coming from variable "new_vibe" wich it's refreshed all time.
      My serie are composed of 15 points, to refresh ma serie, i append to each point the value of the point +1 and i append "new_vibe" to the point 15.

      There is the code of my thread :

      while(1)
      {
                 new_vibe = new_data(); //function that refresh data
      
                 series->clear();
      
                 for(int j=0; j <= 15; j++)
                     {
      
                          if(j == 15)
                              {
                                  graph[j] =  VIBRATION;
                              }
                          else
                              {
                                  graph[j] = graph[j+1];
                              }
      
                          series->append(QPointF(j, graph[j]));
      
                     }
      
                   chart->update();
      
                   QThread::msleep(500);
              }
      
      the refresh process work fine and i check that data are correct, but draws line from , you can see below, i try to append in the order 15 -> 0 but nothing change ! can some one help me ? thanks.
      
      ![ll.png](https://ddgobkiprc33d.cloudfront.net/dabb007e-f54b-43c8-8d80-501c4795b429.png) 
      
      
      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by
      #2

      @jawad_soft

      I have never used QTChart, but I am sure that this code can NOT work.

      You should know that Qt is an asynchronous framework and requires that event loop of thread can be called regularly, so that events and signals/slots can be handled.

      So please avoid forever loops, this will lock the event queue of the thread!

      For your code, I would recommend you to use a QTimer.
      Something like this:

      auto myTimer = new QTimer(this);
      
      connect(myTimer, &QTimer::timeout, this, [this]() {
              series->clear();
              for(int j=0; j <= 15; j++)
              {
                  graph[j] =  (j == 15) ? VIBRATION : graph[j+1];
                  series->append(QPointF(j, graph[j]));
              }
              chart->update();
          });
          
      myTimer->setInterval(500);
      myTimer->start();
      

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      1
      • J Offline
        J Offline
        jawad_soft
        wrote on last edited by jawad_soft
        #3

        @KroMignon thanks ! it's resolve my problem !
        i was thinking that create a specifique thread to refresh my chart will be the best solution, but the wil block all signal and slot of the QTCHART if i understand your explanation, but if i want to to this function in specific thread, should i create and remove the thread every time ? beacause i want to refresh th chart every 100ms and i have anothers (signal -slot) that work with timer ...

        Best regards

        KroMignonK 1 Reply Last reply
        0
        • J jawad_soft

          @KroMignon thanks ! it's resolve my problem !
          i was thinking that create a specifique thread to refresh my chart will be the best solution, but the wil block all signal and slot of the QTCHART if i understand your explanation, but if i want to to this function in specific thread, should i create and remove the thread every time ? beacause i want to refresh th chart every 100ms and i have anothers (signal -slot) that work with timer ...

          Best regards

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by KroMignon
          #4

          @jawad_soft said in QTChart draws line from first to last point:

          i was thinking that create a specifique thread to refresh my chart

          This is also a very bad idea, all graphical items must be in main thread (cf. https://doc.qt.io/qt-5/thread-basics.html).

          but the wil block all signal and slot of the QTCHART if i understand your explanation

          No, what locks the thread event loop, is the forever loop (eg. while(1) {... } or QThread::sleep(), etc. ).

          but if i want to to this function in specific thread, should i create and remove the thread every time ?

          No, why create/destroy thread? But do you really need to use an extra thread ?!?

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          J 1 Reply Last reply
          1
          • KroMignonK KroMignon

            @jawad_soft said in QTChart draws line from first to last point:

            i was thinking that create a specifique thread to refresh my chart

            This is also a very bad idea, all graphical items must be in main thread (cf. https://doc.qt.io/qt-5/thread-basics.html).

            but the wil block all signal and slot of the QTCHART if i understand your explanation

            No, what locks the thread event loop, is the forever loop (eg. while(1) {... } or QThread::sleep(), etc. ).

            but if i want to to this function in specific thread, should i create and remove the thread every time ?

            No, why create/destroy thread? But do you really need to use an extra thread ?!?

            J Offline
            J Offline
            jawad_soft
            wrote on last edited by jawad_soft
            #5

            @KroMignon Thanks for reply,
            i don't really need another thread from the main thread, i'm just asking my self how QT manage all QTIMER when we use many of theme if they have all fast interval ! and maybe in my case if i have one thread manage to refresh data and another that refresh graphic, maybe that will let all the QT APP work well !
            again thanks for your help

            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