Results 1 to 4 of 4

Thread: Qwt Plot not working

  1. #1
    Join Date
    Apr 2014
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Qwt Plot not working

    Hello

    I followed the example of simple plot in qwt examples to plot a curve. The axis and the graph appear in the Qt main window user interface but the curve not. I assigned values to fit the curve but the curve not appear. Any suggestions and help how to solve the problem? Here is my code


    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:nGraphReceived( )
    {
    {
    QMutexLocker locker( &qnode.m_mutex );
    }
    }


    void MainWindow:nParameterReceived( )
    {
    {
    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;
    }
    }


    thanks

  2. #2
    Join Date
    May 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qwt Plot not working

    Hi,

    Perhaps you have the same problem I had...
    I needed to call QwtPlot::replot()

    All I can help with...

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qwt Plot not working

    Quote Originally Posted by astronaut View Post
    I assigned values to fit the curve ...
    Not in the posted code above.

    Uwe

  4. #4
    Join Date
    Apr 2014
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Qwt Plot not working

    Sorry here is the code

    namespace enc = sensor_msgs::image_encodings;
    namespace pow_gui {

    QNode::QNode( int argc, char** argv )
    : init_argc( argc )
    , init_argv( argv )
    , m_parameterCallbackCount( 0 )
    , m_graphCallbackCount( 0 )
    {}

    QNode::~QNode() {
    if(ros::isStarted()) {
    ros::shutdown( ); // explicitly needed since we use ros::start();
    ros::waitForShutdown( );
    }
    wait( );
    }

    bool QNode::initCommon( )
    {

    ros::NodeHandle nh( "~" );
    std::string parameterTopic = nh.resolveName("/stats");
    std::string graphTopic = nh.resolveName("/to_graph");
    m_parameter_subscriber = nh.subscribe<std_msgs::Float64MultiArray>(paramete rTopic, 10, &QNode:arameterCallback, this );
    gsub = nh.subscribe<std_msgs::Float64MultiArray>(graphTop ic, 10, &QNode::graphCallback, this );
    result = 0;
    start();
    return true;
    }

    void QNode:arameterCallback( const std_msgs::Float64MultiArray::ConstPtr& msg )
    {
    std::cout << "parameterCallback " << ++m_parameterCallbackCount << std::endl;
    parameters=msg->data;
    Q_EMIT parameterReceived();
    }

    void QNode::graphCallback( const std_msgs::Float64MultiArray::ConstPtr& msg )
    {
    //std::cout << "graphCallback " << ++m_graphCallbackCount << std::endl;
    ++m_graphCallbackCount;

    linv_g<< QPointF( (float)msg->data[0], (float)msg->data[1] );
    yaw_g<< QPointF( (float)msg->data[0], (float)msg->data[2] );
    trav_g<< QPointF( (float)msg->data[0], (float)msg->data[3] );
    wall_g<< QPointF( (float)msg->data[0], (float)msg->data[4] );
    Q_EMIT graphReceived();

    }

    Here the header files

    class QNode : public QThread {
    Q_OBJECT
    public:
    QNode(int argc, char** argv );
    virtual ~QNode();
    bool init();
    bool init(const std::string &master_url, const std::string &host_url);
    void run();

    /*********************
    ** Logging
    **********************/
    enum LogLevel {
    Debug,
    Info,
    Warn,
    Error,
    Fatal
    };


    inline std::vector<double> get_parameters() { return parameters; }
    QPolygonF linv_g,yaw_g,trav_g,wall_g;
    }

    void parameterReceived();
    void graphReceived();

    private:
    bool initCommon();
    void parameterCallback( const std_msgs::Float64MultiArrayConstPtr& msg );
    void graphCallback( const std_msgs::Float64MultiArrayConstPtr& msg );
    private:
    int init_argc;
    char** init_argv;
    ros::Subscriber m_parameter_subscriber;
    ros::Subscriber gsub;
    float m_parameterCallbackCount;
    float m_graphCallbackCount;
    std::vector<double> parameters;

    And the interface header

    public Q_SLOTS:
    /******************************************
    ** Auto-connections (connectSlotsByName( ))
    *******************************************/
    void onScoreReceived( );
    void onParameterReceived( );
    void onGraphReceived( );

    inline QPolygonF get_linv_g() { return qnode.linv_g; }
    inline QPolygonF get_yaw_g() { return qnode.yaw_g; }
    inline QPolygonF get_trav_g() { return qnode.trav_g; }
    inline QPolygonF get_wall_g() { return qnode.wall_g; }

    private:
    Ui::MainWindowDesign ui;
    QNode qnode;
    std::stringstream ss1, ss2;

    Plot *d_plot;
    QwtPlot* p_plot;
    QwtPlotCurve *curve;
    };

    }

    #endif

Similar Threads

  1. Replies: 3
    Last Post: 26th August 2013, 08:24
  2. Replies: 1
    Last Post: 17th April 2012, 10:10
  3. Replies: 2
    Last Post: 5th May 2010, 06:01
  4. Sticks on plot not working
    By giusepped in forum Qwt
    Replies: 3
    Last Post: 11th February 2009, 09:55
  5. Sticks on plot not working
    By giusepped in forum Qwt
    Replies: 0
    Last Post: 10th February 2009, 07:19

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.