Results 1 to 20 of 59

Thread: How i can plot result in my GUI ?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How i can plot result in my GUI ?

    this is an instance of MainWindow class. New data signal should be connected to plotting slot.
    Don't take it literally if I write "in main:" in comment, I meant mainWindow gui code.

  2. The following user says thank you to stampede for this useful post:

    21did21 (6th June 2011)

  3. #2
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: How i can plot result in my GUI ?

    i have try this, but it still don't work.
    => but now i have less problem of compilation


    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "MyMainWindow.h"
    3. #include <QGridLayout>
    4. #include "RunSimulation.h"
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication app(argc, argv);
    8. MyMainWindow fenetre;
    9. fenetre.show();
    10. return app.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 
    MyMainWindows
    Qt Code:
    1. ---------.h---------
    2. #ifndef MYMAINWINDOW_H
    3. #define MYMAINWINDOW_H
    4.  
    5. #include <QApplication>
    6. #include <QWidget>
    7. #include <QPushButton>
    8. #include <QMessageBox>
    9. #include <qwt_plot_curve.h>
    10. #include <qwt_plot.h>
    11.  
    12. class MyMainWindow : public QWidget
    13. {
    14. Q_OBJECT
    15.  
    16. public:
    17. explicit MyMainWindow(QWidget* parent = 0);
    18. void myRunSlot();
    19. void plotValuesFromFunction(std::vector<double>);
    20.  
    21. private:
    22. QPushButton *BUTTONRun;
    23. QPushButton *BUTTONQuit;
    24. QPushButton *BUTTONAbout;
    25. QPushButton *BUTTONContact;
    26.  
    27. QwtPlot *myPlot1;
    28. QwtPlot *myPlot2;
    29. QwtPlot *myPlot3;
    30. QwtPlot *myPlot4;
    31. QwtPlot *myPlot5;
    32. QwtPlot *myPlot6;
    33.  
    34. QwtPlotCurve myCurve1;
    35. QwtPlotCurve myCurve2;
    36. QwtPlotCurve myCurve3;
    37. QwtPlotCurve myCurve4;
    38. QwtPlotCurve myCurve5;
    39. QwtPlotCurve myCurve6;
    40.  
    41. };
    42. #endif // MYMAINWINDOW_H
    43. ---------.cpp------
    44. #include "MyMainWindow.h"
    45. #include <QGridLayout>
    46. #include <QHBoxLayout>
    47. #include <qwt_plot_curve.h>
    48. #include "RunSimulation.h"
    49. #include <vector>
    50.  
    51. using namespace std;
    52. MyMainWindow::MyMainWindow(QWidget* parent) : QWidget(parent)
    53. {
    54. QGridLayout* mainLayout = new QGridLayout();
    55. setLayout(mainLayout);
    56.  
    57. myPlot1 = new QwtPlot();
    58. myPlot2 = new QwtPlot();
    59. myPlot3 = new QwtPlot();
    60. myPlot4 = new QwtPlot();
    61. myPlot5 = new QwtPlot();
    62. myPlot6 = new QwtPlot();
    63.  
    64. myPlot1->setMinimumSize(200, 100);
    65. myPlot2->setMinimumSize(200, 100);
    66. myPlot3->setMinimumSize(200, 100);
    67. myPlot4->setMinimumSize(200, 100);
    68. myPlot5->setMinimumSize(200, 100);
    69. myPlot6->setMinimumSize(200, 100);
    70.  
    71. QWidget* buttonWidget = new QWidget();
    72. QGridLayout* buttonLayout = new QGridLayout();
    73.  
    74. BUTTONRun = new QPushButton("RUN");
    75. BUTTONQuit = new QPushButton("STOP");
    76. BUTTONAbout = new QPushButton("About");
    77. BUTTONContact = new QPushButton("Contact");
    78.  
    79. buttonLayout->addWidget(BUTTONRun ,0,0);
    80. buttonLayout->addWidget(BUTTONQuit ,0,1);
    81. buttonLayout->addWidget(BUTTONAbout ,1,0);
    82. buttonLayout->addWidget(BUTTONContact,1,1);
    83.  
    84. buttonWidget->setLayout(buttonLayout);
    85.  
    86. mainLayout->addWidget(myPlot1 ,0,0,1,1);
    87. mainLayout->addWidget(myPlot2 ,0,1,1,1);
    88. mainLayout->addWidget(myPlot3 ,0,2,1,1);
    89. mainLayout->addWidget(myPlot4 ,1,0,1,1);
    90. mainLayout->addWidget(myPlot5 ,1,1,1,1);
    91. mainLayout->addWidget(myPlot6 ,1,2,1,1);
    92. mainLayout->addWidget(buttonWidget ,0,3,1,1);
    93.  
    94. myCurve1.attach(myPlot1);
    95. myCurve2.attach(myPlot2);
    96. myCurve3.attach(myPlot3);
    97. myCurve4.attach(myPlot4);
    98. myCurve5.attach(myPlot5);
    99. myCurve6.attach(myPlot6);
    100.  
    101. QObject::connect(BUTTONQuit, SIGNAL(clicked()), qApp, SLOT(quit()));
    102. QObject::connect(BUTTONAbout, SIGNAL(clicked()), qApp, SLOT(aboutQt()));
    103. QObject::connect(BUTTONRun, SIGNAL(clicked()), qApp, SLOT(myRunSlot()));
    104. }
    105. void MyMainWindow::plotValuesFromFunction(vector<double>points)
    106. {
    107. QVector<double> x(1);
    108. QVector<double> y(1);
    109.  
    110. x.append( points[0] );
    111. y.append( points[1] );
    112.  
    113. myCurve1.setSamples(x.data(),y.data(),x.size());
    114. myCurve2.setSamples(x.data(),y.data(),x.size());
    115. myCurve3.setSamples(x.data(),y.data(),x.size());
    116. myCurve4.setSamples(x.data(),y.data(),x.size());
    117. myCurve5.setSamples(x.data(),y.data(),x.size());
    118. myCurve6.setSamples(x.data(),y.data(),x.size());
    119. myPlot1->replot();
    120. myPlot2->replot();
    121. myPlot3->replot();
    122. myPlot4->replot();
    123. myPlot5->replot();
    124. myPlot6->replot();
    125. myPlot1->show();
    126. myPlot2->show();
    127. myPlot3->show();
    128. myPlot4->show();
    129. myPlot5->show();
    130. myPlot6->show();
    131. }
    132. void MyMainWindow::myRunSlot()
    133. {
    134. RunSimulation(this);
    135. }
    To copy to clipboard, switch view to plain text mode 
    RunSimulation
    Qt Code:
    1. --.h--------
    2. #ifndef RUNSIMULATION_H
    3. #define RUNSIMULATION_H
    4. void RunSimulation();
    5. #endif // RUNSIMULATION_H
    6. -.cpp-------
    7. #include <QApplication>
    8. #include <qwt_plot.h>
    9. #include <qwt_plot_curve.h>
    10. #include <vector>
    11. #include "function.h"
    12. #include "RunSimulation.h"
    13. #include "MyMainWindow.h"
    14.  
    15. using namespace std;
    16. void RunSimulation( MyMainWindow * mainWindow )
    17. {
    18. vector<double> points;
    19. for (int i=1;i<10;i++)
    20. {
    21. points.clear();
    22. points=function();
    23. mainWindow->plotValuesFromFunction(points);
    24. //!! for each "i" i want to send result to the 6plots... but i don't know how...?
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 
    function
    Qt Code:
    1. --.h-------
    2. #ifndef FUNCTION_HPP
    3. #define FUNCTION_HPP
    4. std::vector<double> function();
    5. #endif // FUNCTION_HPP
    6. --.cpp-----
    7. #include <vector>
    8. #include <ctime> // to generate random point
    9. #include <cstdlib> // to generate random point
    10. #include "function.h"
    11. #include "windows.h"
    12. using namespace std;
    13. vector<double> function()
    14. {
    15. vector<double> points;
    16. srand(time(0));
    17. points.clear();
    18. Sleep(1);
    19. points.push_back(rand() % 1800);
    20. points.push_back(rand() % 500);
    21. return points;
    22. }
    To copy to clipboard, switch view to plain text mode 

  4. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How i can plot result in my GUI ?

    What do you mean by "don't work" ?

  5. #4
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: How i can plot result in my GUI ?

    thank you for your help

    Quote Originally Posted by stampede View Post
    What do you mean by "don't work" ?
    yes, excuse me.
    when i compile my programm the GUI appear but when i click on the "run button" the points don't appear on the chart

  6. #5
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How i can plot result in my GUI ?

    Is the slot method called ? Add some debugging messages to know what's going on during execution.

  7. #6
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: How i can plot result in my GUI ?

    Quote Originally Posted by stampede View Post
    Is the slot method called ? Add some debugging messages to know what's going on during execution.
    i don't know if the slot method is called.

    I don't know how i can show message during execution because "cout" don't work because i am not in a console projet...

    can you explain me how i can do this

  8. #7
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How i can plot result in my GUI ?

    If you are using windows, add CONFIG += console to project's .pro file, then you can output to stdout any message using qDebug()
    I think it will work without the extra CONFIG if you run your app with gdb, qDebug() output should be visible in debugger message window

  9. The following user says thank you to stampede for this useful post:

    21did21 (11th June 2011)

  10. #8
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: How i can plot result in my GUI ?

    thank you,i haven't compilation's problem but where the console appear?

    during debug i have this error (remark: exempleForum is the name of my project):
    Object::connect: No such slot QApplication::myRunSlot() in ..\2exempleForum\MyMainWindow.cpp:61
    Object::connect: (receiver name: 'exempleForum')
    main


    with this code i just change the prototype of the function :

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "MyMainWindow.h"
    3. #include <QGridLayout>
    4. #include "RunSimulation.h"
    5. #include <QtDebug>
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9. MyMainWindow fenetre;
    10. qDebug()<<"main ";
    11. fenetre.show();
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    MyMainWindows
    Qt Code:
    1. -------------h--------------------
    2. #ifndef MYMAINWINDOW_H
    3. #define MYMAINWINDOW_H
    4. #include <QApplication>
    5. #include <QWidget>
    6. #include <QPushButton>
    7. #include <QMessageBox>
    8. #include <qwt_plot_curve.h>
    9. #include <qwt_plot.h>
    10. class MyMainWindow : public QWidget
    11. {
    12. Q_OBJECT
    13. public:
    14. explicit MyMainWindow(QWidget* parent = 0);
    15. void myRunSlot();
    16. void plotValuesFromFunction(std::vector<double>);
    17. private:
    18. QPushButton *BUTTONRun;
    19. QPushButton *BUTTONQuit;
    20. QPushButton *BUTTONAbout;
    21. QPushButton *BUTTONContact;
    22. QwtPlot *myPlot1;
    23. QwtPlot *myPlot2;
    24. QwtPlot *myPlot3;
    25. QwtPlot *myPlot4;
    26. QwtPlot *myPlot5;
    27. QwtPlot *myPlot6;
    28. QwtPlotCurve myCurve1;
    29. QwtPlotCurve myCurve2;
    30. QwtPlotCurve myCurve3;
    31. QwtPlotCurve myCurve4;
    32. QwtPlotCurve myCurve5;
    33. QwtPlotCurve myCurve6;
    34. };
    35. #endif // MYMAINWINDOW_H
    36. -------------cpp----------------
    37. #include "MyMainWindow.h"
    38. #include <QGridLayout>
    39. #include <QHBoxLayout>
    40. #include <qwt_plot_curve.h>
    41. #include "RunSimulation.h"
    42. #include <vector>
    43. #include <QtDebug>
    44. using namespace std;
    45. MyMainWindow::MyMainWindow(QWidget* parent) : QWidget(parent)
    46. {
    47. QGridLayout* mainLayout = new QGridLayout();
    48. setLayout(mainLayout);
    49. myPlot1 = new QwtPlot();
    50. myPlot2 = new QwtPlot();
    51. myPlot3 = new QwtPlot();
    52. myPlot4 = new QwtPlot();
    53. myPlot5 = new QwtPlot();
    54. myPlot6 = new QwtPlot();
    55. myPlot1->setMinimumSize(200, 100);
    56. myPlot2->setMinimumSize(200, 100);
    57. myPlot3->setMinimumSize(200, 100);
    58. myPlot4->setMinimumSize(200, 100);
    59. myPlot5->setMinimumSize(200, 100);
    60. myPlot6->setMinimumSize(200, 100);
    61. QWidget* buttonWidget = new QWidget();
    62. QGridLayout* buttonLayout = new QGridLayout();
    63. BUTTONRun = new QPushButton("RUN");
    64. BUTTONQuit = new QPushButton("STOP");
    65. BUTTONAbout = new QPushButton("About");
    66. BUTTONContact = new QPushButton("Contact");
    67. buttonLayout->addWidget(BUTTONRun ,0,0);
    68. buttonLayout->addWidget(BUTTONQuit ,0,1);
    69. buttonLayout->addWidget(BUTTONAbout ,1,0);
    70. buttonLayout->addWidget(BUTTONContact,1,1);
    71. buttonWidget->setLayout(buttonLayout);
    72. mainLayout->addWidget(myPlot1 ,0,0,1,1);
    73. mainLayout->addWidget(myPlot2 ,0,1,1,1);
    74. mainLayout->addWidget(myPlot3 ,0,2,1,1);
    75. mainLayout->addWidget(myPlot4 ,1,0,1,1);
    76. mainLayout->addWidget(myPlot5 ,1,1,1,1);
    77. mainLayout->addWidget(myPlot6 ,1,2,1,1);
    78. mainLayout->addWidget(buttonWidget ,0,3,1,1);
    79. myCurve1.attach(myPlot1);
    80. myCurve2.attach(myPlot2);
    81. myCurve3.attach(myPlot3);
    82. myCurve4.attach(myPlot4);
    83. myCurve5.attach(myPlot5);
    84. myCurve6.attach(myPlot6);
    85. QObject::connect(BUTTONQuit, SIGNAL(clicked()), qApp, SLOT(quit()));
    86. QObject::connect(BUTTONAbout, SIGNAL(clicked()), qApp, SLOT(aboutQt()));
    87. QObject::connect(BUTTONRun, SIGNAL(clicked()), qApp, SLOT(myRunSlot()));
    88. }
    89. void MyMainWindow::plotValuesFromFunction(vector<double>points)
    90. {
    91. QVector<double> x(1);
    92. QVector<double> y(1);
    93. x.append( points[0] );
    94. y.append( points[1] );
    95. myCurve1.setSamples(x.data(),y.data(),x.size());
    96. myCurve2.setSamples(x.data(),y.data(),x.size());
    97. myCurve3.setSamples(x.data(),y.data(),x.size());
    98. myCurve4.setSamples(x.data(),y.data(),x.size());
    99. myCurve5.setSamples(x.data(),y.data(),x.size());
    100. myCurve6.setSamples(x.data(),y.data(),x.size());
    101. myPlot1->replot();
    102. myPlot2->replot();
    103. myPlot3->replot();
    104. myPlot4->replot();
    105. myPlot5->replot();
    106. myPlot6->replot();
    107. myPlot1->show();
    108. myPlot2->show();
    109. myPlot3->show();
    110. myPlot4->show();
    111. myPlot5->show();
    112. myPlot6->show();
    113. }
    114. void MyMainWindow::myRunSlot()
    115. {
    116. qDebug()<<"method my run slot ";
    117. RunSimulation(this);
    118. }
    To copy to clipboard, switch view to plain text mode 
    runSimulation
    Qt Code:
    1. ---------------h-----------------
    2. #ifndef RUNSIMULATION_H
    3. #define RUNSIMULATION_H
    4. #include "MyMainWindow.h"
    5. void RunSimulation( MyMainWindow *fenetre );
    6. #endif // RUNSIMULATION_H
    7. ---------------cpp---------------
    8. #include <QApplication>
    9. #include <qwt_plot.h>
    10. #include <qwt_plot_curve.h>
    11. #include <vector>
    12. #include "function.h"
    13. #include "RunSimulation.h"
    14. #include "MyMainWindow.h"
    15. #include <QtDebug>
    16. using namespace std;
    17. void RunSimulation( MyMainWindow *fenetre )
    18. {
    19. qDebug()<<"run simlation ";
    20. vector<double> points;
    21. for (int i=1;i<10;i++)
    22. {
    23. points.clear();
    24. points=function();
    25. fenetre->plotValuesFromFunction(points);
    26. //!! for each "i" i want to send result to the 6plots... but i don't know how...?
    27. }
    28. }
    To copy to clipboard, switch view to plain text mode 
    function
    Qt Code:
    1. -------------------h-------------
    2. #ifndef FUNCTION_HPP
    3. #define FUNCTION_HPP
    4. std::vector<double> function();
    5. #endif // FUNCTION_HPP
    6. ------------cpp-----------------
    7. #include <vector>
    8. #include <ctime> // to generate random point
    9. #include <cstdlib> // to generate random point
    10. #include "function.h"
    11. #include "windows.h"
    12. #include <QtDebug>
    13. using namespace std;
    14. vector<double> function()
    15. {
    16. qDebug()<<"function ";
    17. vector<double> points;
    18. srand(time(0));
    19. points.clear();
    20. //Sleep(1);
    21. points.push_back(rand() % 1800);
    22. points.push_back(rand() % 500);
    23. return points;
    24. }
    To copy to clipboard, switch view to plain text mode 

  11. #9
    Join Date
    May 2011
    Posts
    21
    Thanks
    1
    Thanked 5 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How i can plot result in my GUI ?

    QObject::connect(BUTTONRun, SIGNAL(clicked()), qApp, SLOT(myRunSlot()));
    qApp (QApplication instance) doesn't have a myRunSlot() slot. "this" has one.

    QObject::connect(a, SIGNAL(a()), this, SLOT(b())); = connect(a, SIGNAL(a()), SLOT(b()));

  12. The following user says thank you to Troudhyl for this useful post:

    21did21 (7th June 2011)

  13. #10
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: How i can plot result in my GUI ?

    i have replace this:
    QObject::connect(BUTTONRun, SIGNAL(clicked()), qApp, SLOT(myRunSlot()));

    by:

    QObject::connect(BUTTONRun, SIGNAL(clicked()), this, SLOT(myRunSlot()));

    now i haven't error but it still don't works...

  14. #11
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How i can plot result in my GUI ?

    you have to declare "myRunSlot()" as slot:

    Qt Code:
    1. public slots:
    2. void myRunSlot();
    To copy to clipboard, switch view to plain text mode 

  15. The following user says thank you to FelixB for this useful post:

    21did21 (8th June 2011)

  16. #12
    Join Date
    May 2011
    Posts
    122
    Thanks
    34
    Platforms
    Windows

    Default Re: How i can plot result in my GUI ?

    yes it's a mistake! thanks a lot!!! it resolve a problem

    but one problem continue:
    => my curve appear just at the end, the point are not ploting during execution
    Last edited by 21did21; 8th June 2011 at 09:24.

Similar Threads

  1. QRegExp - get only last result
    By kabanek in forum Newbie
    Replies: 2
    Last Post: 3rd November 2010, 22:17
  2. How to display result
    By sksingh73 in forum Newbie
    Replies: 1
    Last Post: 7th June 2010, 08:39
  3. QSqlQuery return result
    By arpspatel in forum Qt Programming
    Replies: 2
    Last Post: 9th April 2010, 07:55
  4. Result of DBUS call
    By conexion2000 in forum Qt Programming
    Replies: 4
    Last Post: 28th July 2009, 08:34
  5. Replies: 7
    Last Post: 22nd September 2008, 22:05

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.