Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 高CPU使用率的树莓皮Qt绘图_C++_Qt_Plot_Raspberry Pi_Cross Compiling - Fatal编程技术网

C++ 高CPU使用率的树莓皮Qt绘图

C++ 高CPU使用率的树莓皮Qt绘图,c++,qt,plot,raspberry-pi,cross-compiling,C++,Qt,Plot,Raspberry Pi,Cross Compiling,我在Raspberry pi B+上使用Qt creator交叉编译来开发一个应用程序,从文件中绘制数据。该程序在我的笔记本电脑上运行良好,但绘图在pi B+上使用hi处理。当我在笔记本电脑上运行程序时,它的CPU占用率不到1%,在pi上的CPU占用率为1-2%,当我在笔记本电脑上开始绘图时,它占用大约13%的CPU,而在pi上,它占用大约95-99%的CPU!!!。在我的笔记本电脑上绘图每秒超过60帧,但在pi上只有每秒14-16帧,当我超频pi时,我得到了每秒35帧。我的笔记本电脑使用gno

我在Raspberry pi B+上使用Qt creator交叉编译来开发一个应用程序,从文件中绘制数据。该程序在我的笔记本电脑上运行良好,但绘图在pi B+上使用hi处理。当我在笔记本电脑上运行程序时,它的CPU占用率不到1%,在pi上的CPU占用率为1-2%,当我在笔记本电脑上开始绘图时,它占用大约13%的CPU,而在pi上,它占用大约95-99%的CPU!!!。在我的笔记本电脑上绘图每秒超过60帧,但在pi上只有每秒14-16帧,当我超频pi时,我得到了每秒35帧。我的笔记本电脑使用gnome外壳运行Ubuntu14.04,CPU是intel centrino core 2 Dou 2 GHz,带有4 GB RAM和NVIDIA。这是我的Qt应用程序的源代码

    #include "mainwindow.h"
    #include "ui_mainwindow.h"


    ///*********** STARTING THE CLASS **************************///
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);

        MainWindow::plotting();
    //********************* Read File **************************//
        QFile inputFile("ECG_Data.txt");
        if (inputFile.open(QIODevice::ReadOnly))
        {
           QTextStream in(&inputFile);
           int i=0;
           while (!in.atEnd())
           {
              QString line = in.readLine();
              fileData[i]=line.toDouble();
              i++;
           }
           inputFile.close();
        }

    }


    ///**************** START BUTTON *************************///
    void MainWindow::on_pushButton_clicked()
    {
        stop= true;
    }
    ///***************** STOP BUTTON **************************///
    void MainWindow::on_pushButton_2_clicked()
    {
        stop = false;

    }

    ///**************** PLOTTING *******************************///
    void MainWindow::plotting()
    {
    //***** set plot parameters *******************************//
        ui->customPlot->addGraph();
        ui->customPlot->graph(0)->setPen(QPen(Qt::yellow)); //set plot line color
        ui->customPlot->xAxis->setTickLabelType(QCPAxis::ltDateTime);
        ui->customPlot->xAxis->setDateTimeFormat("hh:mm:ss");
        ui->customPlot->xAxis->setAutoTickStep(false);
        ui->customPlot->xAxis->setTickStep(2);
        ui->customPlot->axisRect()->setupFullAxesBox();

    //***** set plot background color ****************************//
        QLinearGradient plotGradient;
        plotGradient.setStart(0, 0); //set start point
        plotGradient.setFinalStop(0, 350); //set final point
        plotGradient.setColorAt(1, QColor(100, 100, 100)); // set background color
        ui->customPlot->setBackground(plotGradient);

    //***** creat connection for plot Axes *************************//
        // make left and bottom axes transfer their ranges to right and top axes:
        connect(ui->customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->xAxis2, SLOT(setRange(QCPRange)));
        connect(ui->customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->customPlot->yAxis2, SLOT(setRange(QCPRange)));


    //***** creat connection for plot founction *********************//
        // setup a timer that repeatedly calls MainWindow::realtimeDataSlot();
        connect(&dataTimer, SIGNAL(timeout()), this, SLOT(readResponse()));
        dataTimer.start(10); // Interval 0 means to refresh as fast as possible

    }

///**************** REAL TIME PLOTTING SLOT *********************///
    void MainWindow::readResponse()

    { if(j==500){j=0;}

        double value0 = fileData[j];
        if (stop)
        {j++;
    //***** calculate two new data points: **************************//
        double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0; //first data point of plot from time
        static double lastPointKey = 0;
        if (key-lastPointKey > 0.01) // at most add point every 10 ms
        { //emit plottingData(rx);
        //  double value0 = rxplot; // convert string data of serial port to Double to be the second data point of plot

    //***** add data to lines: *****************************//
          ui->customPlot->graph(0)->addData(key, value0);
          // remove data of lines that's outside visible range:
          ui->customPlot->graph(0)->removeDataBefore(key-2);
          ui->customPlot->graph(0)->rescaleValueAxis();
          lastPointKey = key;
        }
//make key axis range scroll with the data (at a constant range size of 8):
        ui->customPlot->xAxis->setRange(key+0.25, 2, Qt::AlignRight);
        ui->customPlot->replot();

//***** calculate frames per second: *********************************//
        static double lastFpsKey;
        static int frameCount;
        ++frameCount;
         if (key-lastFpsKey > 2) // average fps over 2 seconds
         { ui->statusBar->showMessage(QString("%1 FPS, Total Data points: %2").arg(frameCount/(key-lastFpsKey), 0, 'f', 0).arg(ui->customPlot->graph(0)->data()->count()), 0 );
          lastFpsKey = key;
          frameCount = 0;
         }
         }

    }

    ///****************** DESTRUCTOR ****************************///
    MainWindow::~MainWindow()
    {
        delete ui;

    }
该应用程序在pi上全屏运行“这是第二个问题”,并且不接收来自触摸屏的触摸事件。我使用Qt5.4,在pi上,操作系统是Raspbian Wheezy。我用这个指令来配置pi上的交叉编译


请帮助我:(

Pi的CPU非常非常慢。这并不奇怪。除了将绘图移植到GL之外,您没有什么可以做的。@ddriver或使用更高效的CPU渲染。有一系列CPU绘图技术,不需要在每一帧重新绘制整个图形。或者,您知道,不要浪费时间在消除线条锯齿之类的事情上s、 ddriver&PeterT,谢谢你的快速重播。我确实增加了GPU内存,但没有发生任何事情。你建议如何改进渲染?你建议我购买吗pi2@QudorEng我建议您尝试使用新的QtCharts库。我还想指出,当前的qcustomplot没有那么强大和优化。@tty6您认为QtChart需要les吗它的处理比qcustumplot好吗?