Results 1 to 9 of 9

Thread: QUpdSocket The program has unexpectedly finished.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2014
    Location
    Spain
    Posts
    14
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QUpdSocket The program has unexpectedly finished.

    Hello,
    VirtualBox, openSUSE13.1, Qt Creator 2.8 Qt4.8
    I want to receive data to other machine to my application but now I want to check and I have a application to write a message and another to read messages, but the application to write unexpectedly finished.

    In the .h:

    QUdpSocket *udpSocket;
    QTimer *timer;


    Application to read
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QUdpSocket>
    4. #include <QByteArray>
    5. #include <string.h>
    6.  
    7. MainWindow::MainWindow(QWidget *parent) :
    8. QMainWindow(parent),
    9. ui(new Ui::MainWindow)
    10. {
    11. ui->setupUi(this);
    12. initSocket();
    13. }
    14.  
    15. MainWindow::~MainWindow()
    16. {
    17. delete ui;
    18. }
    19.  
    20. void MainWindow::initSocket()
    21. {
    22. udpSocket = new QUdpSocket(this);
    23. udpSocket->bind(QHostAddress::LocalHost, 7755);
    24.  
    25. connect(udpSocket, SIGNAL(readyRead()),this, SLOT(readPendingDatagrams()));
    26. emit SIGNAL(readyRead());
    27. }
    28.  
    29. void MainWindow::readPendingDatagrams()
    30. {
    31. while (udpSocket->hasPendingDatagrams()) {
    32. QByteArray datagram;
    33. datagram.resize(udpSocket->pendingDatagramSize());
    34. QHostAddress sender;
    35. quint16 senderPort;
    36.  
    37. udpSocket->readDatagram(datagram.data(), datagram.size(),&sender, &senderPort);
    38. processTheDatagram(datagram);
    39. }
    40. }
    41.  
    42.  
    43. void MainWindow::processTheDatagram(QByteArray datagram)
    44. {
    45. QDataStream in(&datagram, QIODevice::ReadOnly);
    46.  
    47. for(int i=0;i<datagram.size();i++){
    48. //ui->label_2->setText(datagram.at(i).toString());
    49. ui->label_2->setText("Recibido");
    50. }
    51. }
    To copy to clipboard, switch view to plain text mode 

    Application to write
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3.  
    4. MainWindow::MainWindow(QWidget *parent) :
    5. QMainWindow(parent),
    6. ui(new Ui::MainWindow)
    7. {
    8. ui->setupUi(this);
    9. initSocket();
    10. }
    11.  
    12. MainWindow::~MainWindow()
    13. {
    14. delete ui;
    15. }
    16.  
    17. void MainWindow::initSocket()
    18. {
    19. udpSocket = new QUdpSocket(this);
    20. udpSocket->bind(QHostAddress::LocalHost, 7755);
    21.  
    22. connect(timer, SIGNAL(timeout()), this, SLOT(sendDatagram()));
    23. timer->start(2*1000);
    24. }
    25.  
    26. void MainWindow::sendDatagram()
    27. {
    28. QByteArray datagram_send;
    29.  
    30. datagram_send.append("Mensaje 1");
    31. udpSocket->writeDatagram(datagram_send.data(),datagram_send.size(),QHostAddress::LocalHost, 7755);
    32. }
    To copy to clipboard, switch view to plain text mode 
    Maybe to check I don't need another application to check and only a method to write and call it when I initialize the QUpdSocket.
    Any idea?? thanks
    Last edited by anda_skoa; 18th September 2014 at 10:56. Reason: missing [code] tags

Similar Threads

  1. The program has unexpectedly finished.
    By smemamian in forum Newbie
    Replies: 4
    Last Post: 1st April 2013, 00:44
  2. Replies: 4
    Last Post: 17th September 2012, 15:23
  3. the program has unexpectedly finished
    By narlapavan in forum Qt Programming
    Replies: 9
    Last Post: 9th July 2012, 09:04
  4. Replies: 6
    Last Post: 24th June 2012, 18:32
  5. Program has unexpectedly finished
    By Maluko_Da_Tola in forum Newbie
    Replies: 5
    Last Post: 1st December 2010, 09:54

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.