title: Qt GUI for UDP packet reception
body: <p>I am developing a GUI using Qt for a test UDP server application i wrote in C using the sockets interface available in unix. I aim of the GUI is to display all the messages (perror and fprintf) in either a "text edit box" or "text browser box". Here is my code, </p>
  
  <pre><code> //-----------------------------Main.Cpp------------------------------------------//
  
  //-----------------------------QT specific headers-------------------------------//
  #include "mainwindow.h"
  #include &lt;QApplication&gt;
  #include &lt;QLabel&gt;
  //------------------------------------------------------------------------------------//
  
  
  int main(int argc, char *argv[])
  {
  int sock_fd=0;
  funct_class funct_class_obj;
  QApplication a(argc, argv);
  MainWindow w;
  sock_fd=funct_class_obj.udp_config();
  funct_class_obj.recv_fucnt(sock_fd);
  
  return a.exec();
  }
  //--------------------------------End of main.cpp------------------------------//
  
  //-----------------------------mainwindow.cpp----------------------------------//
  
  //-----------------------------QT specific headers-----------------------------//
  #include "mainwindow.h"
  #include "ui_mainwindow.h"
  #include &lt;QApplication&gt;
  #include &lt;QLabel&gt;
  //-----------------------------------------------------------------------------//
  
  
  //--------------------------------C program specific headers------------------//
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include&lt;sys/socket.h&gt;
  #include&lt;netinet/in.h&gt;
  #include&lt;arpa/inet.h&gt;
  #include&lt;sys/types.h&gt;
   //---------------------------------------------------------------------------//
  
  
  unsigned char message[50];
  
  QString mystr;
  
  int funct_class:: udp_config()
  {
       int sock_fd=0;
  
       if ((sock_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) &lt; 0)
          perror("\nError creating socket\n");
           //mystr = "\nError creating socket\n";
  
  
       else
       {
          fprintf(stdout, "\nSuccessfully created socket with descriptor:%d\n", sock_fd);
          //mystr = "Successfully created socket";
  
          struct sockaddr_in sock_addr = {0};
          sock_addr.sin_family = AF_INET;
          sock_addr.sin_port = htons(PORT);
          if (inet_aton("127.0.0.1", &amp;sock_addr.sin_addr) &lt; 0)
          perror("\nError converting destination IP address from dotted decimal to     binary\n");
          //    mystr = "Error converting destination IP address from dotted decimal to binary";
  
       else
       {
          if (bind(sock_fd, (struct sockaddr*)&amp;sock_addr, sizeof(sock_addr)) &lt; 0)                         // Bind function call binds the properties assigned above to the socket created earlier
          perror("\nError binding the port and IP address with the socket\n");
          //mystr = "Error binding the port and IP address with the socket";
  
       else
          fprintf(stdout, "\nBinding port and IP address successful\n");
          //    mystr = "Binding port and IP address successful";
  
       }
       }
  
       return sock_fd;
  }
  
  
  
  void funct_class:: recv_fucnt(int sock_fd)
  {
      struct sockaddr_in recv_sockaddr = {0};
      socklen_t recv_sockaddr_len = sizeof(recv_sockaddr);
      int recv_data=0;
  
      if ((recv_data = recvfrom(sock_fd, message, sizeof(message), 0x00, (struct     sockaddr*)&amp;recv_sockaddr, &amp;recv_sockaddr_len)) &lt;= 0)
  
          perror("\nError receiving data/no data received\n");
          //mystr = "Error receiving data/no data received";
  
  
          else
          fprintf(stdout, "\nSuccessfully received %d bytes of data\n", recv_data);
      fprintf(stdout, "\nData is :%s", message);
             //mystr = "Successfully received data";
      mystr = QString::fromStdString((const char*)message);
  
  
  }
  
  
  
  MainWindow::MainWindow(QWidget *parent) :
  QMainWindow(parent),
  ui(new Ui::MainWindow)
  {
  ui-&gt;setupUi(this);
  ui-&gt;testedit-&gt;setText(mystr);
  //ui-&gt;mytextbrowser-&gt;setText((mystr));
  }
  
  
  
  MainWindow::~MainWindow()
  {
  delete ui;
  }
  
  //-----------------------------End of mainwindow.cpp---------------------------//
  
  //------------------------------------mainwindow.h-----------------------------//
  
  #ifndef MAINWINDOW_H
  #define MAINWINDOW_H
  
  #include &lt;QMainWindow&gt;
  
  #define PORT 5030
  
  
  namespace Ui {
  class MainWindow;
  }
  
  class MainWindow : public QMainWindow
  {
  Q_OBJECT
  
  public:
  explicit MainWindow(QWidget *parent = 0);
  ~MainWindow();
  
  
  private:
  Ui::MainWindow *ui;
  };
  
  
  class funct_class{
  
  public:
  int udp_config();
  void recv_fucnt(int sock_fd);
  
  };
  
  
  
  
   #endif // MAINWINDOW_H
  
  
  //-------------------------------End of mainwindow.h-----------------------------//
  </code></pre>
  
  <p>The application is compiling fine, but i am facing problems when i execute it. It just freezes and even if i manage to get it out from freeze, i am not able to display the required string either in the "text edit box" or "text browser box". Please help.</p>
  
  <p>P.S.: I am a newbie to GUI programming and Cpp. </p>