Hi there. I have a problem I would like you to help me with. Here is my code.

Qt Code:
  1. #include "qplotter.h"
  2.  
  3. QPlotter::QPlotter(QMainWindow *parent) :
  4. QMainWindow(parent)
  5. {
  6. create_actions();
  7. create_file_test("d:\\my_projects\\1.txt");
  8. read_file("d:\\my_projects\\1.txt");
  9. create_menus();
  10. plot_item();
  11.  
  12. //connect(loadFileAction, SIGNAL(triggered()), this, SLOT(repaint()));
  13. }
  14.  
  15. void QPlotter::repaint()
  16. {
  17. funPlot->resize(this->size());
  18. }
  19.  
  20. void QPlotter::plot_item()
  21. {
  22. QwtPlotCurve* temp_curve = new QwtPlotCurve();
  23. QPen pen = QPen(Qt::blue);
  24. temp_curve->setRenderHint(QwtPlotItem::RenderAntialiased);
  25. temp_curve->setPen(pen);
  26. temp_curve->setData(y_points, x_points);
  27. temp_curve->setVisible(true);
  28. temp_curve->setTitle("Channel 1, blue");
  29.  
  30. funPlot = new QwtPlot(this);
  31. funPlot->setTitle("Channel 1");
  32. temp_curve->attach(funPlot);
  33.  
  34. funPlot->resize(800, 600);
  35.  
  36. QwtLegend* legend = new QwtLegend(this);
  37. funPlot->insertLegend(legend, QwtPlot::RightLegend, -1.0);
  38.  
  39. this->resize(funPlot->size());
  40.  
  41. this->repaint();
  42. }
  43.  
  44. void QPlotter::create_actions()
  45. {
  46. loadFileAction = new QAction(tr("Load file..."),this);
  47. saveCurveAsImageAction = new QAction(tr("Save as image..."), this);
  48. }
  49.  
  50. void QPlotter::create_menus()
  51. {
  52. fileMenu = new QMenu();
  53. this->menuBar()->addMenu(fileMenu);
  54.  
  55. fileMenu->setTitle("File");
  56. fileMenu->addAction(loadFileAction);
  57. fileMenu->addAction(saveCurveAsImageAction);
  58. }
  59.  
  60. void QPlotter::create_file_test(char* name)
  61. {
  62. FILE* in_file;
  63. in_file = fopen(name, "w");
  64.  
  65. //create and fill vectors with test values
  66. std::vector<float> a, b;
  67.  
  68. for (int i = 0; i < 10000; i+=50) a.push_back(i);
  69. for (int i = 0; i < 200; i++) b.push_back(i);
  70.  
  71. for (int i = 0; i < 200; i++) fprintf(in_file, "%f %f\n", b[i], a[i]);
  72. fclose(in_file);
  73. }
  74.  
  75. void QPlotter::read_file(char* name)
  76. {
  77. FILE* in_file;
  78. in_file = fopen(name, "r");
  79.  
  80. rewind(in_file);
  81.  
  82. float* temp1 = (float*)calloc(1, sizeof(float));
  83. float* temp2 = (float*)calloc(1, sizeof(float));
  84. while (!feof(in_file))
  85. {
  86. fscanf(in_file, "%f %f", temp1, temp2);
  87. x_points.push_back(*temp1);
  88. y_points.push_back(*temp2);
  89. }
  90.  
  91. int k = 0;
  92.  
  93. free(temp1);//free allocated memory
  94. free(temp2);//free allocated memory
  95. }
To copy to clipboard, switch view to plain text mode 

But after executing plot_item(), the menu is no longer clickable. If create_menus() is placed after plot_item(), everything works. What am I doing wrong? Thank you in advance.