Writing Data to a UDP socket error and stack error



  • This is my configuration:

    @
    void IOProcessor::button()
    {
    char udpDataOut[2];
    // build byte array
    udpDataOut[0] = 0x23;
    udpDataOut[1] = 0x00;
    // send data
    flag = udpSocket.write(udpDataOut, 2);
    checkSendStatus(flag);
    }

    void checkSendStatus(int status)
    {
    if(status < 0){
    // display message box
    QMessageBox msgBox;
    msgBox.setText("Data was unable to be sent to IO Processor");
    msgBox.exec();
    }
    }
    @

    I do have a lot more going on in the app other than this, but this is just one occasion that I need to send data. I am getting a -1 returned every time when trying to send data. I am already receiving data constantly on the port which means I am connected. That is why I dont use readDatagram(). After clicking the button that triggers the udp send and closing out of the program, I get a stack error. This is AFTER I close the program in my console window.

    *** glibc detected *** /home/dvez/Desktop/CEI_QtApp-build-desktop/CEI_QtApp: free(): invalid pointer: 0x0000000000619650 ***
    ======= Backtrace: =========
    /lib/x86_64-linux-gnu/libc.so.6(+0x78a8f)[0x7f70a4be1a8f]
    /lib/x86_64-linux-gnu/libc.so.6(cfree+0x73)[0x7f70a4be58e3]
    /home/dvez/QtSDK/Desktop/Qt/473/gcc/lib/libQtCore.so.4(_ZN14QObjectPrivate14deleteChildrenEv+0x50)[0x7f70a5a590c0]
    /home/dvez/QtSDK/Desktop/Qt/473/gcc/lib/libQtGui.so.4(_ZN7QWidgetD2Ev+0x29b)[0x7f70a633ae9b]
    /home/dvez/Desktop/CEI_QtApp-build-desktop/CEI_QtApp[0x4067f3]
    /home/dvez/Desktop/CEI_QtApp-build-desktop/CEI_QtApp[0x404a7f]
    /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xff)[0x7f70a4b87eff]
    /home/dvez/Desktop/CEI_QtApp-build-desktop/CEI_QtApp[0x404969]

    with a ton more mumbo jumbo that I am not really sure what it means. I have no experience with Qt and sending and receiving data. Although, I am receiving data correctly from my device, it just wont send. I am thinking its a memory issue with the fact I am not allocating memory for something I should be. But, I thought when you initialize a char[] pointer array, it allocates memory already. Or maybe I am not freeing it correctly? It could be possible that the memory is not being free'ed on the program close, yet that still doesn't explain why I am not able to send data correctly. The device has its own protocol and is currently working with a vb application using the same byte arrays shown below. So, I know that the device is working properly. Remember, this is a very large project, and this is 1 of 15 times I would like to send udpData Out the socket, and the program is constantly reading data from the socket.

    I can post more info on the issue if needed.

    Anyone have any ideas for what could be happening or enlighten me in the proper way to output data on the udp socket?

    Thanks in advance!

    Edit: Here is my close function as well
    @
    Connect::~Connect()
    {
    char udpDataOut[2];
    // build byte array
    udpDataOut[0] = 0x22; // 1st byte
    udpDataOut[1] = 0x00; // 2nd byte
    // send data
    flag = udpSocket.write(udpDataOut, 2);
    checkSendStatus(flag);

    // delete the ui and close the application
    delete ui;
    

    }
    @



  • Could you show the class definition and the constructor? (or all the code, if you're at it, a zipped project is always good).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.