Hi all,

I've developed a GUI application in which when you click on a button, you start a connection process, opening a socket, waiting for a "Ready" message, sending a "Connection Resquest" and waiting for a "Connection Complete". The connection process is ended when you received the last message, very simple. Moreover, the application has two items in the main menu, one of them choose the IP server of the socket and the other one closes the application.

At first, the application runs correctly, the socket is opened and the messages are sent. When this process ends, the application has nothing to do, except it should respond if you click one of the two options in the menu. However, after 3 or 4 seconds the widget becomes darker and I cannot click on the menu. If I try to close directly the widget, a message appears saying: "Application does not respond".

Any idea? Where is the error?

Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4.  
  5.  
  6.  
  7. MainWindow::MainWindow(QWidget *parent) :
  8. QMainWindow(parent),
  9. ui(new Ui::MainWindow)
  10. {
  11. ui->setupUi(this);
  12.  
  13. connect(ui->actionSalir, SIGNAL(triggered()), this, SLOT(close()));
  14. connect(ui->actionConfiguraci_n, SIGNAL(triggered()), this, SLOT(configurar()));
  15.  
  16. this->IP_from_config = "192.168.1.190";
  17. estadoReady();
  18.  
  19.  
  20. }
  21.  
  22.  
  23.  
  24. MainWindow::~MainWindow()
  25. {
  26. delete ui;
  27. }
  28.  
  29.  
  30. void MainWindow::configurar()
  31. {
  32. Dialog config;
  33. config.exec();
  34.  
  35. this->IP_from_config = config.IP_address;
  36. }
  37.  
  38.  
  39.  
  40. void MainWindow::inicializando()
  41. {
  42. //Crear colas de comunicación con RRC
  43. socket_client = new CClientSocket();
  44. socket_client->open_socket(this->IP_from_config.toAscii(),"5858");
  45.  
  46. //Esperar mensaje "RRC Ready"
  47. int num_bytes;
  48. bool b_wait = true;
  49. do
  50. {
  51.  
  52. num_bytes = socket_client->read_socket();
  53. if(num_bytes > 0)
  54. {
  55. char* aux_msg = socket_client->get_string_from_buffer(num_bytes);
  56. std::string recv_msg(aux_msg,num_bytes);
  57. if (recv_msg.compare("RRC Ready") == 0)
  58. b_wait = false;
  59. }
  60. usleep(1);
  61.  
  62. }while( b_wait);
  63. std::cout << "Received RRC Ready" << std::endl;
  64.  
  65. }
  66.  
  67. void MainWindow::on_button_Conectar_clicked()
  68. {
  69. inicializando();
  70.  
  71.  
  72. estadoConectando();
  73. QCoreApplication::processEvents();
  74.  
  75. //Send Request
  76. std::string message = "Connection Request";
  77. bool resul;
  78. do{
  79. resul = socket_client->write_socket(message);
  80. usleep(1);
  81.  
  82. }while(!resul);
  83. std::cout << "Sent Connection Request" << std::endl;
  84.  
  85.  
  86. //Esperar mensaje "Connection Complete"
  87. std::string recv_msg;
  88. int num_b;
  89. bool b_wait = true;
  90. do
  91. {
  92. num_b = socket_client->read_socket();
  93. if(num_b > 0)
  94. {
  95. recv_msg = socket_client->get_string_from_buffer(num_b);
  96. if (recv_msg.compare("Connection Complete") == 0)
  97. b_wait = false;
  98. }
  99.  
  100. usleep(1);
  101.  
  102. }while( b_wait);
  103. std::cout << "Received Connection Complete" << std::endl;
  104.  
  105.  
  106.  
  107. estadoConectado();
  108. QCoreApplication::processEvents();
  109. }
  110.  
  111.  
  112. void MainWindow::estadoInicial()
  113. {
  114. //Labels
  115. ui->label->setText(QString::fromUtf8("Estado: Inicializando..."));
  116. ui->label_2->setText("");
  117.  
  118. //Buttons
  119. ui->button_Conectar->setVisible(false);
  120.  
  121. }
  122.  
  123. void MainWindow::estadoReady()
  124. {
  125. //Labels
  126. ui->label->setText(QString::fromUtf8("Estado: Preparado."));
  127. ui->label_2->setText("");
  128.  
  129. //Buttons
  130. ui->button_Conectar->setVisible(true);
  131.  
  132. }
  133.  
  134. void MainWindow::estadoConectando()
  135. {
  136. //Start connection
  137. ui->label->setText(QString::fromUtf8("Estado: Conectando..."));
  138. ui->label_2->setText("");
  139.  
  140. //Update Buttons
  141. ui->button_Conectar->setEnabled(false);
  142.  
  143.  
  144. }
  145.  
  146. void MainWindow::estadoDesconectado()
  147. {
  148. //Labels
  149. ui->label->setText(QString::fromUtf8("Estado: No conectado."));
  150. ui->label_2->setText("");
  151.  
  152.  
  153. ui->button_Conectar->setEnabled(true);
  154.  
  155. }
  156.  
  157. void MainWindow::estadoConectado()
  158. {
  159. //Labels
  160. ui->label->setText(QString::fromUtf8("Estado: Conectado."));
  161. ui->label_2->setText("");
  162.  
  163. //Buttons
  164. ui->button_Conectar->setVisible(false);
  165.  
  166. }
To copy to clipboard, switch view to plain text mode 

Thank you very much.