Hello,
I want to visualize a flowing data with a bar graph. Ive written a test code; but i see some flickers when the graph is being drawn. I know that double buffering is default with qt4. What should I do else to remove the flickers on the screen? The code is below:

main.cpp:
Qt Code:
  1. int main(int argc, char *argv[])
  2. {
  3. #include <QApplication>
  4. #include "anapencere.h"
  5. #include <QGraphicsView>
  6.  
  7. QApplication a(argc, argv);
  8. AnaPencere mAnapencere;
  9. mAnapencere.setSceneRect(0,0,400,250);
  10. view.setScene(&mAnapencere);
  11. view.show();
  12. return a.exec();
  13. }
To copy to clipboard, switch view to plain text mode 

anapencere.h :
Qt Code:
  1. #ifndef ANAPENCERE_H
  2. #define ANAPENCERE_H
  3.  
  4. #include <QGraphicsScene>
  5. #include <QTimer>
  6. #include "bargrapher.h"
  7. #include <sys/time.h>
  8.  
  9. class AnaPencere : public QGraphicsScene
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit AnaPencere(QObject *parent = 0);
  14.  
  15. private:
  16. QTimer mTimer;
  17. BarGrapher *grapher;
  18. int mCurrentTime;
  19. int mPrevTime;
  20. int differ;
  21. int fps;
  22. int textPrinter;
  23. struct timeval tv;
  24.  
  25. private slots:
  26. void updateSlot();
  27.  
  28. };
  29.  
  30. #endif // ANAPENCERE_H
To copy to clipboard, switch view to plain text mode 

bargrapher.h
Qt Code:
  1. #ifndef BARGRAPHER_H
  2. #define BARGRAPHER_H
  3.  
  4. #include <QGraphicsItem>
  5. #include <QList>
  6.  
  7. class BarGrapher : public QGraphicsItem
  8. {
  9. public:
  10. BarGrapher();
  11. QRectF boundingRect() const;
  12. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
  13. void insertData(qreal data );
  14. private:
  15. QList<int> floatingData;
  16. };
  17.  
  18. #endif // BARGRAPHER_H
To copy to clipboard, switch view to plain text mode 

anapencere.cpp :
Qt Code:
  1. #include "anapencere.h"
  2.  
  3. AnaPencere::AnaPencere(QObject *parent) :
  4. {
  5. connect(&mTimer,SIGNAL(timeout()),this,SLOT(updateSlot()));
  6. grapher= new BarGrapher();
  7. addItem(grapher);
  8. fpsText= new QGraphicsTextItem;
  9. fpsText->setPlainText("0");
  10. addItem(fpsText);
  11. mPrevTime=0;
  12. mCurrentTime=0;
  13. textPrinter=0;
  14. mTimer.start(40);
  15. }
  16.  
  17. void AnaPencere::updateSlot()
  18. {
  19. grapher->insertData(rand()%200);
  20. grapher->update();
  21.  
  22. textPrinter++;
  23. gettimeofday(&tv,NULL);
  24. mPrevTime=mCurrentTime;
  25. mCurrentTime = tv.tv_sec % 100000 * 1000;
  26. mCurrentTime += tv.tv_usec/1000 ;
  27. differ= mCurrentTime-mPrevTime;
  28. if(differ!=0)
  29. fps=1000/(differ);
  30. else fps=1000;
  31.  
  32. if(textPrinter%100==0){
  33. fpsText->setPlainText(QString::number(fps)+" fps");
  34. textPrinter=0;
  35. }
  36. }
To copy to clipboard, switch view to plain text mode 

bargrapher.cpp
Qt Code:
  1. #include "bargrapher.h"
  2. #include <QPainter>
  3.  
  4. BarGrapher::BarGrapher()
  5. {
  6. }
  7. QRectF BarGrapher::boundingRect() const
  8. {
  9. return QRectF(0, 0,400, 250);
  10. }
  11.  
  12. void BarGrapher::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
  13. QWidget *widget)
  14. {
  15. painter->setPen(Qt::black);
  16. painter->setBrush(QBrush(Qt::red));
  17. painter->fillRect(QRect(0,0,400,250),Qt::green);
  18. for(int i=0;i<floatingData.size();++i)
  19. {
  20. painter->drawRect(0,floatingData.at(i),10,300);
  21. painter->translate(10,0);
  22. }
  23. if(floatingData.size()>=50)
  24. floatingData.takeFirst();
  25.  
  26. }
  27.  
  28. void BarGrapher::insertData(qreal data)
  29. {
  30. floatingData.append((int)data);
  31. }
To copy to clipboard, switch view to plain text mode