Results 1 to 2 of 2

Thread: GUI blocked

  1. #1
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default GUI blocked

    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.

  2. #2
    Join Date
    Apr 2010
    Location
    Moscow
    Posts
    31
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: GUI blocked

    I've changed the code this way. It works now.
    Qt Code:
    1. void QPlotter::plot_item()
    2. {
    3. QwtPlotCurve* temp_curve = new QwtPlotCurve();
    4. QPen pen = QPen(Qt::blue);
    5. temp_curve->setRenderHint(QwtPlotItem::RenderAntialiased);
    6. temp_curve->setPen(pen);
    7. temp_curve->setData(y_points, x_points);
    8. temp_curve->setVisible(true);
    9. temp_curve->setTitle("Channel 1, blue");
    10.  
    11. funPlot = new QwtPlot(this);
    12. funPlot->setTitle("Channel 1");
    13. temp_curve->attach(funPlot);
    14.  
    15. funPlot->resize(800, 600);
    16. resize(funPlot->size().width() + 10, funPlot->size().height() + 10);
    17.  
    18. QwtLegend* legend = new QwtLegend(this);
    19. funPlot->insertLegend(legend, QwtPlot::RightLegend, -1.0);
    20.  
    21. setCentralWidget(funPlot);
    22. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Setting the system time make the Qt program blocked.
    By alps_xing in forum Qt Programming
    Replies: 0
    Last Post: 10th June 2010, 08:12
  2. how blocked center in QGraphicsScene
    By estel in forum Newbie
    Replies: 3
    Last Post: 20th March 2010, 10:11
  3. GUI thread blocked using QThread.
    By summer_of_69 in forum Qt Programming
    Replies: 11
    Last Post: 18th May 2009, 09:43
  4. QThread event loop seems blocked
    By eurodatar in forum Qt Programming
    Replies: 3
    Last Post: 6th May 2009, 16:50
  5. Replies: 1
    Last Post: 24th February 2009, 18:35

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.