Results 1 to 5 of 5

Thread: Rappresentation of data on diagram

  1. #1
    Join Date
    Mar 2014
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    2

    Default Rappresentation of data on diagram

    I'm tryng to solve an issue with data rappresentation, I know perfectly (by debug) where the error accure, but the context is not very simple to define, due to the extension of the code. Starting to explain the work:

    • The program receives datas from a message broker (activeMq)
      Store these value in a string variable
      Try to show the values received on a diagram

    The relevant code (in my opinion) to understand is this:
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. QPixmap activelogo("C:/Users/Marco/Desktop/CadCamation/Ifacom.JPG");
    10. ui->label_title->setPixmap(activelogo);
    11. setupDiagram();
    12. connectionReceiver();
    13.  
    14. }
    To copy to clipboard, switch view to plain text mode 
    In the previous code be attention to the function setupDiagram implemented here below:
    Qt Code:
    1. void MainWindow::setupDiagram(){
    2. ui->widget_diagram2->addGraph();
    3. ui->widget_diagram2->graph(0)->setPen(QPen(Qt::blue));
    4. ui->widget_diagram2->graph(0)->setAntialiasedFill(false);
    5. ui->widget_diagram2->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    6. ui->widget_diagram2->xAxis->setDateTimeFormat("hh:mm:ss");
    7. ui->widget_diagram2->xAxis->setAutoTickStep(false);
    8. ui->widget_diagram2->xAxis->setTickStep(2);
    9. ui->widget_diagram2->yAxis->setLabel("Average Wire vibrations[%]");
    10. ui->widget_diagram2->axisRect()->setupFullAxesBox();
    11. connect(ui->widget_diagram2->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->widget_diagram2->xAxis2, SLOT(setRange(QCPRange)));
    12. connect(ui->widget_diagram2->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->widget_diagram2->yAxis2, SLOT(setRange(QCPRange)));
    13. ui->widget_diagram2->replot();
    14. }
    To copy to clipboard, switch view to plain text mode 

    After this the diagram is setted in the widget object, and is all ok, so at this point the application wait for a data, and once it is received it is passed to the following function like a double type:
    Qt Code:
    1. void MainWindow::upDateData(double value0){
    2.  
    3.  
    4. double key = QDateTime::currentDateTime().toMSecsSinceEpoch()/1000.0;
    5. static double lastPointKey = 0;
    6. if (key-lastPointKey > 0.01) // at most add point every 10 ms
    7. {
    8.  
    9. ui->widget_diagram2->graph(0)->addData(key, value0);
    10. ui->widget_diagram2->graph(0)->removeDataBefore(key-8);
    11. ui->widget_diagram2->graph(0)->rescaleValueAxis();
    12. lastPointKey = key;
    13. }
    14. ui->widget_diagram2->xAxis->setRange(key+0.25, 8, Qt::AlignRight);
    15. ui->widget_diagram2->replot();
    16. }
    To copy to clipboard, switch view to plain text mode 

    the issue is in the last line, when I try to execute ui->widget_diagram2->replot(), some bad happen and this is the error:

    Cattura.JPG

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Rappresentation of data on diagram

    Looks like upDateData() is not executed by the main thread.

    Where do you call that method from?

    Cheers,
    _

  3. #3
    Join Date
    Mar 2014
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    2

    Default Re: Rappresentation of data on diagram

    ok I call this method in an other function, this function is an automatic function called by default.
    the function is onMessage(const Message* message){.......}...inside this I call upDateData().

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Rappresentation of data on diagram

    Called by default by what? By the main thread? By another thread?

    If it is called by another thread you need to call upDateData() indirectly, e.g. via QMetaObject::invokeMethod(), using Qt::QueuedConnection, or as a signal slot connection using a QueuedConnection.

    Cheers,
    _

  5. #5
    Join Date
    Mar 2014
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    2

    Default Re: Rappresentation of data on diagram

    Ok I understand what you mean, so I think that the solution suggested from you is to implement a directConnection or queueConnection to manage two events that evidently are in two different threads.
    Thank you!

Similar Threads

  1. making a diagram in Qt
    By kadaj in forum Newbie
    Replies: 1
    Last Post: 2nd July 2013, 06:42
  2. Diagram Painting
    By typhoon1978 in forum Qt Programming
    Replies: 4
    Last Post: 2nd November 2010, 23:11
  3. Class Diagram
    By graciano in forum Newbie
    Replies: 1
    Last Post: 16th January 2009, 21:08
  4. needle diagram
    By darksaga in forum Qt Programming
    Replies: 4
    Last Post: 31st March 2008, 12:01
  5. Flow Diagram
    By fruzzo in forum Newbie
    Replies: 5
    Last Post: 2nd December 2007, 19:45

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
  •  
Qt is a trademark of The Qt Company.