Qwt图不起作用,简单的曲线曲线没有出现

时间:2014-06-13 03:21:34

标签: qt plot qwt

我按照Qwt示例中的简单绘图示例来绘制曲线。轴和图形出现在Qt主窗口用户界面中,但曲线没有。我指定的值适合曲线,但曲线没有出现。要绘制的值是向量,并加载到onParameterReceived()中。

有任何建议和帮助如何解决问题?这是我的代码

MainWindow::MainWindow( int argc, char** argv, QWidget *parent )
 : QMainWindow( parent ), qnode( argc,argv )
{
    ui.setupUi( this ); // Calling this incidentally connects all ui's triggers to on_...() callbacks in this class.
    QObject::connect( ui.actionAbout_Qt, SIGNAL( triggered( bool )), qApp, SLOT( aboutQt( ))); // qApp is a global variable for the application
    ReadSettings( );
    setWindowIcon( QIcon( ":/images/icon.png" ));
    ui.tab_manager->setCurrentIndex( 0 ); // ensure the first tab is showing - qt-designer should have this already hardwired, but often loses it (settings?).
    QObject::connect( &qnode, SIGNAL( rosShutdown( )), this, SLOT( close( )));

    /*********************
    ** Logging
    **********************/
    ui.view_logging->setModel( qnode.loggingModel( ));
    QObject::connect( &qnode, SIGNAL( loggingUpdated( )), this, SLOT( updateLoggingView( )));
    QObject::connect( &qnode, SIGNAL( graphReceived( )), this, SLOT( onGraphReceived( )));
    QObject::connect( &qnode, SIGNAL( parameterReceived( )), this, SLOT( onParameterReceived( )));
    /*********************
    ** Auto Start
    **********************/
    if ( ui.checkbox_remember_settings->isChecked( ))
    {
        on_button_connect_clicked( true );
    }
    ui.parameters->setAttribute( Qt::WA_NoMousePropagation );
    ui.parameters->setAttribute( Qt::WA_OpaquePaintEvent );
    ui.plotgraph->setAttribute( Qt::WA_NoMousePropagation );
    ui.plotgraph->setAttribute( Qt::WA_OpaquePaintEvent );

    p_plot = new QwtPlot(ui.plotgraph);
    p_plot->setTitle( "Plot LinVel" );
    p_plot->setCanvasBackground( Qt::white );

    // Axis
    p_plot->setAxisTitle( QwtPlot::xBottom, "Time(sec)" );
    p_plot->setAxisTitle( QwtPlot::yLeft, "Linear Velocity (m/sec)" );
    p_plot->setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    p_plot->setAxisScale( QwtPlot::xBottom, 0.0, 50.0 );
    p_plot->insertLegend( new QwtLegend() );

    //samplingThread.start();
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->attach( p_plot );

    curve = new QwtPlotCurve();
    curve->setTitle( "Linear velocity" );

    // Set curve styles
    curve->setPen( Qt::blue, 4 ),
    curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );   
    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
    QBrush( Qt::yellow), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
    curve->setSymbol( symbol);

    // Assign values to the curve
    //curve->setSamples(ui.plotgraph.get_linv_g());//yaw_g,trav_g,wall_g;
    curve->attach( p_plot );

    p_plot->resize( 600, 400 );
    p_plot->show();
}

void MainWindow::onGraphReceived( )
{
      QMutexLocker locker( &qnode.m_mutex ); 
}


void MainWindow::onParameterReceived( )
{
      QMutexLocker locker( &qnode.m_mutex );
      std::vector<double> p_ = qnode.get_parameters();
      std::cout << p_[0]<<" "<<p_[1]<<" "<<p_[2]<<" "<<p_[3]<<" "<<p_[4] << std::endl;
}

任何帮助?

0 个答案:

没有答案