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. Help about QChart and repainting it
Forum Updated to NodeBB v4.3 + New Features

Help about QChart and repainting it

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 1.0k 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.
  • K Offline
    K Offline
    KuriGohan
    wrote on last edited by KuriGohan
    #1

    Hello everyone, I'm new in this community, as well as in QT programming and GUI programming. I'm using QT Creator to develop a project for the university and, since I don't have much knowledge about how programming a GUI except a bit of C#, I'm sure some of my questions could sound stupid.
    First of all, one of the page of my GUI should plot a QChart though a QChartView. In it there is a QScatterSeries with 0 points at first. Then, around every minute, in the final version of the project a thread should create a list of points to be added and a list of points to be removed, let's call it T1, which is a non-GUI thread (potentially written with standard C++ library, non QT) focused on collecting data (e.g. though socket connections on a LAN). At the moment, let's focus just on the list of points to add.
    My idea is the following: when the T1 has collected all the data (every minute, every 1.5 minutes) signals it with a std::condition_variable. I did that the GUI thread, when creating the layout, uses a thread (let's call T2) of the QThreadPool::globalInstance() to wait for the notification on this condition variable.
    Then, I tried to pass the pointer of the QScatterSeries to the istance of the subclass of QRunnable and in the method run I wrote the following code:

      *series << QPointF(x, y)<< QPointF(x, y+1)<< QPointF(x, y+2)<< QPointF(x, y+3)<< QPointF(x, y+4);
    

    And I noticed that these points are immadiately showed on the screen! But this T2 is a thread of the pool, not the GUI thread. How is it possible? Or it's normal but I should avoid? I thought that in the method run I should have emited a signal to slot which the GUi thread should have executed, to repaint the QChartView.
    Another question: this way am I paint a point at time? What could I do do add many points and showing them all together?

    I hope to have been the clearest as possible, and thank you for the attention!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MrShawn
      wrote on last edited by MrShawn
      #2

      Been a few months since I did some stuff with QCharts....

      If I remember right you add series to the chart - in which case when you modify the series, you will see that modification right away, From what I am seeing you are dereferencing a pointer that is likely to that series. Regardless of thread, if you have a pointer it will write to the original address and that is probably why you are getting this unexpected behavior.

      1 Reply Last reply
      1
      • K Offline
        K Offline
        KuriGohan
        wrote on last edited by
        #3

        Yes, you're perfectly right. So is it legit what I did, or is it against the principle of GUi Programming?

        Besides I tried to do the followinf double for cycle:

        for(x=0; x < 15; x+=0.2)
                    for(y=0; y < 10; y +=0.2, count++)
                        series->insert(count, QPointF(x, y));
        

        And it works in both the GUI Thread and T2, but I imagined the GUi immediately freezes and can't continua to work, so I should find a way to process all the series together I suppose..

        JonBJ 1 Reply Last reply
        0
        • K KuriGohan

          Yes, you're perfectly right. So is it legit what I did, or is it against the principle of GUi Programming?

          Besides I tried to do the followinf double for cycle:

          for(x=0; x < 15; x+=0.2)
                      for(y=0; y < 10; y +=0.2, count++)
                          series->insert(count, QPointF(x, y));
          

          And it works in both the GUI Thread and T2, but I imagined the GUi immediately freezes and can't continua to work, so I should find a way to process all the series together I suppose..

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

          @KuriGohan

          1. QSeries << operator (https://doc.qt.io/qt-5.11/qxyseries.html#operator-lt-lt) is just the same as QSeries::append(). I don't know whether QSeries::insert() is any slower than append() (try it and see?), otherwise I would expect them to take the same amount of time.

          2. The difference is your second code is adding a lot more points than your first!

          3. I think there was a thread recently where we were discussing the speed/GUI "freeze" when adding lots of points. You're adding say 2,500 points. That takes time! You can make the GUI be more responsive by calling http://doc.qt.io/qt-5/qcoreapplication.html#processEvents() intermittently, e.g. each time round your x loop (not too frequently, though, else it will actually slow things down; I think we found every 100 points or so was good). Also, you are adding your points one at a time; something like https://doc.qt.io/qt-5.11/qxyseries.html#append-2 adds a list, I can't recall if we found that was any faster.

          1 Reply Last reply
          3

          • Login

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