Results 1 to 3 of 3

Thread: How to use a curve with values other than Double?

  1. #1
    Join Date
    Sep 2015
    Location
    Ontario, Canada
    Posts
    28
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default How to use a curve with values other than Double?

    I have a server that I'm reading different signal data off of and I want to plot the data using a qwtPlotCurve as it comes in. My problem is that some of the data comes in as an unsigned type (Uint64_t, ulongong, ushort, etc) but setRawSamples only supports arrays of double, so my data gets misinterpreted and comes out as really funny numbers except for the signals that are of signed types.

    I had a similar problem with displaying my data in a table, but since the data is stored as a QVariant all I had to do was make a large switch block and cast the data as I updated it, and make a custom delegate for displaying it.

    However, since setRawSamples only supports signed types I can't do this and was wondering if there was another way around it so that i could have curves being plotted of both signed and unsigned types.

    My code for updating the plot as it is now is below for reference:

    Qt Code:
    1. void TableViewWindow::UpdateTrendViewDocks(uint64_t **storedData)
    2. {
    3. //If this ViewWindow has been closed do nothing
    4. if (this->isHidden())
    5. return;
    6.  
    7. QList<QDockWidget *> allDockWidgets = findChildren<QDockWidget *>();
    8.  
    9. for (QDockWidget * eachDock : allDockWidgets)
    10. {
    11. //Only update docks that are visible
    12. if (!eachDock->isHidden())
    13. {
    14. TableDock *thisTableDock = static_cast<TableDock *>(eachDock);
    15. // Check if the dock contains a trendview before attempting to update
    16. if (thisTableDock->GetViewType() == TableDock::TrendView)
    17. {
    18. QwtPlot *theTrendView = static_cast<QwtPlot *>(thisTableDock->widget());
    19. for (TableDock::CurvePair *curvePair : thisTableDock->curveHolder)
    20. {
    21. curvePair->curve->setRawSamples(xAxisCounter
    22. , (double *)storedData[curvePair->sigNumber]
    23. , historyCount);
    24. double ** demoContainer= (double **)storedData;
    25.  
    26. std::cerr << std::dec << "SignNum " << curvePair->sigNumber
    27. << " Should = " << *((uint64_t * )&demoContainer[curvePair->sigNumber][2999])
    28. << " double Value = " << *((double * )&demoContainer[curvePair->sigNumber][2999])
    29. << std::endl;
    30. }
    31. theTrendView->replot();
    32. }
    33. }
    34. }
    35. }
    To copy to clipboard, switch view to plain text mode 

    With a sample output line from this using a signal where the only difference is whether it's interpreted as signed or unsigned being:

    Qt Code:
    1. SignNum 0 Should = 6693 double Value = 3.30678e-320
    To copy to clipboard, switch view to plain text mode 

    Note that storedData is of type uint64_t **
    Also note the letsPretend variable and cerr print statement was for proof of concept and isn't actually going to be in the final run as it does nothing but show the error I'm getting
    Last edited by TEAmerc; 26th October 2015 at 20:33. Reason: Clarification

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

    Default Re: How to use a curve with values other than Double?

    If you don't want to convert and copy the samples to a 2nd buffer you can write a data bridge deriving from QwtSeriesData<QPointF> using your original samples. If the values in xAxisCounter are somehow related to the sample index you could avoid to have this array too.

    But of course you can't simply cast a pointer for an uint64_t * to double * and expect to happen something useful.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    TEAmerc (27th October 2015)

  4. #3
    Join Date
    Sep 2015
    Location
    Ontario, Canada
    Posts
    28
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to use a curve with values other than Double?

    After some experimentation I got a data bridge derived from QwtSeriesData<QPointF> like you suggested working on the plot similarly to my delegate class for the table side.

    Also the xAxisCounter was literally just an array of incrementing values for a counter along the x-Axis so this method also did let me get rid of that too which was nice.

    Thanks!

Similar Threads

  1. Replies: 2
    Last Post: 28th August 2012, 02:53
  2. How to obtain values of a zoomed curve ?
    By Hogwarts in forum Qwt
    Replies: 3
    Last Post: 7th June 2012, 15:12
  3. Replies: 2
    Last Post: 23rd February 2012, 01:11
  4. Retrieve Curve values
    By nenukino in forum Qwt
    Replies: 2
    Last Post: 26th February 2008, 14:33
  5. Progress Bar with double values
    By ^NyAw^ in forum Qt Programming
    Replies: 8
    Last Post: 23rd March 2007, 15:37

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.