Results 1 to 10 of 10

Thread: Regarding qt real time plot using qml wrapper for Qcustomplot

  1. #1
    Join Date
    Aug 2016
    Posts
    14
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Regarding qt real time plot using qml wrapper for Qcustomplot

    I am using the following wrapper: https://github.com/ncp1402/ql-lineplot to plot the data in real-time, I could plot the data in a static manner (not real time) however, on trying the below code (relevant for realtime), my application crashes (no error message)

    Qt Code:
    1. import QtQuick 2.0
    2.  
    3. import 'src/qml'
    4. import QtQuick.Layouts 1.2
    5. QlLinePlot { id:plot; Layout.fillWidth:true; Layout.fillHeight:true;
    6.  
    7. // X/Y labels
    8. labelX: 'time'
    9. labelY: 'Values'
    10.  
    11. // show legend
    12. legend: true
    13.  
    14. // enable/disable autorange
    15. autoRange: true
    16.  
    17. // enable/disable X/Y mouse drag
    18. dragX: true
    19. dragY: true
    20.  
    21. // enable/disable X/Y mouse zoom (with Shift - only X, with Ctrl - only Y)
    22. zoomX: true
    23. zoomY: true
    24.  
    25. // enable/disable time/date format for X axis
    26. xDate: true
    27. // time/date format
    28. xDateFormat: 'hh.mm.ss'
    29. yPrev:[4,2,3]
    30.  
    31. property var colors: ['red']
    32. property var names: ['T1']
    33. Timer{
    34. id:textTimer
    35. interval:1000
    36. repeat:true
    37. running:true
    38. triggeredOnStart: true
    39. // initialize plot
    40. Component.onCompleted: {
    41. // remove all graphs
    42. //clearGraphs();
    43. // add new graphs
    44. for (var i=0; i <= colors.length; i++)
    45. addGraph(names[i], true, colors[i], 3, 'solid');
    46.  
    47. var i1=0;
    48. while(adcreader.hasSample()) //check whether a sample is present or not
    49. {
    50.  
    51. plot.addPoints(i1, [adcreader.getSample()]); //get it and plot
    52. i1++;
    53. }
    54. plot.visible= true;
    55.  
    56. }
    57. }
    58.  
    59. }
    To copy to clipboard, switch view to plain text mode 

    I think there is some mistake in the way I have tried to plot, since, I don't have experience of using Qt, any suggestions regarding the changes required will be great!
    Last edited by user03; 26th August 2016 at 18:21.

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

    Default Re: Regarding qt real time plot using qml wrapper for Qcustomplot

    How does that even load?
    The import for QlLinePlot is missing.

    It also doesn't have any size unless it has some implicit size or is put into a layout at the place this is instantiated from.

    Also the timer seems to be useless as its triggered signal is not handled.

    Cheers,
    _

  3. #3
    Join Date
    Aug 2016
    Posts
    14
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Regarding qt real time plot using qml wrapper for Qcustomplot

    Quote Originally Posted by anda_skoa View Post
    How does that even load?
    The import for QlLinePlot is missing.
    _
    It also doesn't have any size unless it has some implicit size or is put into a layout at the place this is instantiated from.

    Also the timer seems to be useless as its triggered signal is not handled.

    Cheers,


    That is import 'qml' and I could plot the data properly without running it in real time. Could you suggest an appropriate way to get it done in real time?

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

    Default Re: Regarding qt real time plot using qml wrapper for Qcustomplot

    Quote Originally Posted by user03 View Post
    That is import 'qml' and I could plot the data properly without running it in real time.
    I see.
    I mistook the Q1LinePlot with the Q1LinePlotItem that is registered in C++. I guess this is used inside th Q1LinePlot.qml

    Quote Originally Posted by user03 View Post
    Could you suggest an appropriate way to get it done in real time?
    Your data source needs to notify the QML side then it has new data, and then you need to update the plot.

    Cheers,
    _

  5. #5
    Join Date
    Aug 2016
    Posts
    14
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Regarding qt real time plot using qml wrapper for Qcustomplot

    Okay, I have defined two slots called hasSample and getSample, hasSample when queried returns true/false (boolean) and getSample returns the value to be plotted (int). Below are the two functions

    Qt Code:
    1. int Classname::getSample()
    2. {
    3. int ret= buff[outp];
    4. outp=(outp+1)%100;
    5. return ret;
    6. }
    7. //return size
    8. bool Classname::hasSample() const
    9. {
    10. if(inp==outp)
    11. return false;
    12. else
    13. return true;
    14. }
    15.  
    16. //statements from another function in .cpp that gets the value:
    17. buff[inp]=foo; //value added in the buffer
    18. inp=(inp+1)%100;
    To copy to clipboard, switch view to plain text mode 

    Kkindly correct me if this not the proper way to get it done. Also, I found this link: http://doc.qt.io/qt-5/qtqml-cppinteg...mlfromcpp.html . May be I need to access the QQmlProperty? Thank you.
    Last edited by user03; 27th August 2016 at 11:11.

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

    Default Re: Regarding qt real time plot using qml wrapper for Qcustomplot

    Quote Originally Posted by user03 View Post
    Okay, I have defined two slots called hasSample and getSample, hasSample when queried returns true/false (boolean) and getSample returns the value to be plotted (int). Below are the two functions
    Yes, these look ok and you already said they work.

    As I said in my last comment, you need to notify the QML side about new data.
    So add a signal and emit it when new data arrives.

    Then you react to that signal in QML, e.g. by connecting a function to it or by using a Connections element.

    In both cases I would recommend to move the code that clears and fills the plot into a function.
    Then it can be called from onCompleted and the signal handler.

    Quote Originally Posted by user03 View Post
    Also, I found this link: http://doc.qt.io/qt-5/qtqml-cppinteg...mlfromcpp.html . May be I need to access the QQmlProperty? Thank you.
    No, this has nothing to do with what you need here.

    Cheers,
    _

  7. #7
    Join Date
    Aug 2016
    Posts
    14
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Regarding qt real time plot using qml wrapper for Qcustomplot

    I could finally get the signal part in .cpp done but I am still not sure on how to make qml read the changed signal value every time, I could get a static plot but how can I make sure that every signal emitted event gets a response in qml plot.
    I tried below code in qml:
    Component.onCompleted: {
    var i1=0;
    while(1)
    {
    plot.addPoints(i1, [adcreader.t]); //integer t is the updated value
    i1++;
    }
    }

    However, the application crashes each time (due to while loop but I don't know how else can I make it to constantly check the updated value)
    Last edited by user03; 28th August 2016 at 18:15.

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

    Default Re: Regarding qt real time plot using qml wrapper for Qcustomplot

    1) in QML add a function to the QlLinePlot item.
    2) in that function clear all points and call your addPoints loop
    3) verify that everything works when you call that function from Component.onCompleted.

    Then add this to the Component.onCompleted
    Qt Code:
    1. adcreader.yourSignalName.connect(yourFunctionName);
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  9. #9
    Join Date
    Aug 2016
    Posts
    14
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Regarding qt real time plot using qml wrapper for Qcustomplot

    Okay, thanks for the help, I'll try these things now, however,

    Quote Originally Posted by anda_skoa View Post
    Then you react to that signal in QML, e.g. by connecting a function to it or by using a Connections element.
    _

    Could you please tell me if you are referring to something of this sort:
    Q_PROPERTY(int t READ ai NOTIFY aiChanged)

    and this aiChanged signal should be emitted by the method which gets the updated value? I am totally confused about this signal and slot concept

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

    Default Re: Regarding qt real time plot using qml wrapper for Qcustomplot

    Quote Originally Posted by user03 View Post
    Could you please tell me if you are referring to something of this sort:
    Q_PROPERTY(int t READ ai NOTIFY aiChanged)

    and this aiChanged signal should be emitted by the method which gets the updated value? I am totally confused about this signal and slot concept
    Not quite.

    You don't need a property if you keep using your "hasSamples" and "getSample" methods, just the signal to notify the QML side that it has to call these again.

    But the signal declaration is bascially equal to how you would declare the aiChanged signal and you emit it the same way as the uiChanged signal.

    Cheers,
    _

Similar Threads

  1. Qwt real-time plot memory problem
    By speak_no_evil in forum Qwt
    Replies: 1
    Last Post: 20th November 2014, 10:20
  2. How to real time plot?
    By RafaelRSE in forum Qwt
    Replies: 2
    Last Post: 7th August 2014, 18:14
  3. Replies: 3
    Last Post: 12th April 2013, 06:18
  4. real time graph plot
    By robotics in forum Qt Programming
    Replies: 5
    Last Post: 24th May 2011, 05:04
  5. QFileSystemWatcher with a Qwt Real-time plot
    By gen_mass in forum Qt Programming
    Replies: 1
    Last Post: 25th June 2010, 21:28

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.