Results 1 to 4 of 4

Thread: QT GUI is running (need to refresh the plot for new data with pushbutton)

  1. #1
    Join Date
    Feb 2011
    Posts
    2
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Cool QT GUI is running (need to refresh the plot for new data with pushbutton)

    Hi,

    I have implemented simple qwt plot application and i have added pushbutton this application reads data from bin file and plots it.

    Now when i start application it plots the data from file, now I want
    "on button press(which will invoke comand based program and save new bin file in same diractory) to capture new data and put in the file and after that it shud refresh the plot with new file.
    but some how its not working.
    here is my code

    Qt Code:
    1. int main(int argc, char **argv)
    2. {
    3.  
    4. QApplication a(argc, argv);
    5. Plot plot;
    6. QPushButton FFT("FFT",&plot);
    7. FFT.resize(75, 30);
    8. FFT.setFont(QFont("Times", 18, QFont::Bold));
    9. QObject::connect(&FFT, SIGNAL(clicked()), &Plot(), SLOT(replot()));
    10. plot.resize(600,400);
    11. plot.show();
    12.  
    13.  
    14. return a.exec();
    15. }
    To copy to clipboard, switch view to plain text mode 

    //////////////////

    I want to run following code again when i press the pushbutton FFT
    Qt Code:
    1. system("./readwritegpp readwrite.out 0xC4F5B000 16392 1");
    2. FILE *fin;
    3. float *ptr;
    4.  
    5. fin = fopen( "test.bin", "rb" ); //rb means read-binary
    6.  
    7. for (int count=0; count<4096 ; count++)
    8. {
    9. fread( &val[count], 1, 4, fin ); //size of float = 4 bytes
    10. nPoints[count]=count;
    11. fft_db[count]=val[count];
    12.  
    13. }
    14.  
    15. fclose(fin);
    16. fft->setData(nPoints, fft_db, 4096);
    To copy to clipboard, switch view to plain text mode 


    can anyone help me?
    Last edited by high_flyer; 28th April 2011 at 15:29. Reason: code tags

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT GUI is running (need to refresh the plot for new data with pushbutton)

    I want to run following code again when i press the pushbutton FFT
    all you have to do is pack that code in to a slot, and connect the clicked() signal from the button to this slot.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Feb 2011
    Posts
    2
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT GUI is running (need to refresh the plot for new data with pushbutton)

    thank you, well I have declared a new slot and put this code in its implementation

    but when i compile code it gives
    Object::connect: No such slot QwtPlot::checkValues()

    this is my code

    Qt Code:
    1. #include <qapplication.h>
    2. #include <qwt_plot.h>
    3. #include <qwt_plot_marker.h>
    4. #include <qwt_plot_curve.h>
    5. #include <qwt_legend.h>
    6. #include <qwt_data.h>
    7. #include <qwt_text.h>
    8. #include <qwt_math.h>
    9. #include <math.h>
    10. #include <QFile>
    11. #include <QLabel>
    12. #include <QDataStream>
    13. #include <QTextStream>
    14. #include <iostream>
    15. #include <fstream>
    16. #include <QPushButton>
    17. #include <stdlib.h>
    18. #include <QFont>
    19. #include <qobject.h>
    20. #include <QObject>
    21.  
    22.  
    23. /* this is later the memory content in L3 (128kByte)*/
    24.  
    25. double fft_db[4096];
    26. double nPoints[4096];
    27. float val[4096];
    28. using namespace std;
    29.  
    30. //-----------------------------------------------------------------
    31. // simple.cpp
    32. //
    33. // A simple example which shows how to use QwtPlot for FFT
    34. //-----------------------------------------------------------------
    35.  
    36.  
    37.  
    38. class Plot : public QwtPlot
    39. {
    40. public:
    41. Plot();
    42.  
    43. private slots:
    44. void checkValues();
    45.  
    46.  
    47. };
    48.  
    49.  
    50. Plot::Plot()
    51. {
    52.  
    53. setAutoReplot(false);
    54. setTitle("Single Tone FFT_Plot");
    55. insertLegend(new QwtLegend(), QwtPlot::RightLegend);
    56.  
    57. // Set axis titles
    58. setAxisTitle(xBottom, "Fs -->");
    59. setAxisTitle(yLeft, "FFT Magnitude(dB) -->");
    60.  
    61. // Insert new curves
    62. QwtPlotCurve *fft = new QwtPlotCurve("y = fft(x)");
    63. #if QT_VERSION >= 0x040000
    64. fft->setRenderHint(QwtPlotItem::RenderAntialiased);
    65. #endif
    66. fft->setPen(QPen(Qt::blue));
    67. fft->attach(this);
    68. setAxisScale(QwtPlot::xBottom, 0.0, 2048.0);
    69. setAxisScale(QwtPlot::yLeft, 0.0, 160.0);
    70.  
    71. system("./readwritegpp readwrite.out 0xC4F5B000 16392 1");
    72. FILE *fin;
    73.  
    74. fin = fopen( "test.bin", "rb" ); //rb means read-binary
    75.  
    76. for (int count=0; count<4096 ; count++)
    77. {
    78. fread( &val[count], 1, 4, fin ); //size of float = 4 bytes
    79. nPoints[count]=count;
    80. fft_db[count]=val[count];
    81.  
    82. }
    83.  
    84. fclose(fin);
    85. fft->setData(nPoints, fft_db, 2048);
    86.  
    87.  
    88.  
    89. // Insert markers
    90.  
    91. // ...a horizontal line at y = 0...
    92. mY->setLabel(QString::fromLatin1("y = 0"));
    93. mY->setLabelAlignment(Qt::AlignRight|Qt::AlignTop);
    94. mY->setLineStyle(QwtPlotMarker::HLine);
    95. mY->setYValue(0.0);
    96. mY->attach(this);
    97.  
    98. // ...a vertical line at x = 2 * pi
    99. mX->setLabel(QString::fromLatin1("x = 2 pi"));
    100. mX->setLabelAlignment(Qt::AlignLeft | Qt::AlignBottom);
    101. mX->setLabelOrientation(Qt::Vertical);
    102. mX->setLineStyle(QwtPlotMarker::VLine);
    103. mX->setLinePen(QPen(Qt::black, 0, Qt::DashDotLine));
    104. mX->setXValue(M_PI);
    105. mX->attach(this);
    106.  
    107. replot();
    108.  
    109. }
    110.  
    111.  
    112. void Plot:: checkValues()
    113. {
    114. system("./readwritegpp readwrite.out 0xC4F5B000 16392 1");
    115. }
    116.  
    117.  
    118.  
    119.  
    120. int main(int argc, char **argv)
    121. {
    122.  
    123.  
    124. QApplication a(argc, argv);
    125.  
    126.  
    127.  
    128. Plot plot;
    129.  
    130. QPushButton FFT("FFT",&plot);
    131. FFT.resize(75, 30);
    132. FFT.setFont(QFont("Times", 18, QFont::Bold));
    133.  
    134. QObject::connect(&FFT, SIGNAL(clicked()), &Plot(), SLOT(checkValues()));
    135.  
    136. plot.resize(600,400);
    137.  
    138. plot.show();
    139.  
    140.  
    141. return a.exec();
    142.  
    143. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by high_flyer; 29th April 2011 at 14:15. Reason: code tags

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: QT GUI is running (need to refresh the plot for new data with pushbutton)

    thats because you defined your slot as private.
    Define it as public.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Replies: 5
    Last Post: 19th November 2010, 17:02
  2. Simple Plot after Inputing some Data
    By thebrute in forum Qwt
    Replies: 0
    Last Post: 18th August 2010, 15:29
  3. Plot does not refresh
    By Mat12345 in forum Qwt
    Replies: 3
    Last Post: 21st October 2009, 23:45
  4. 2D array data plot!
    By kahramonj in forum Qwt
    Replies: 3
    Last Post: 21st March 2009, 12:48
  5. plot only subset of the data
    By pospiech in forum Qwt
    Replies: 3
    Last Post: 14th April 2008, 22:19

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.