Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. Qt Contribution
  4. Segmentation fault error
Forum Updated to NodeBB v4.3 + New Features

Segmentation fault error

Scheduled Pinned Locked Moved Qt Contribution
2 Posts 2 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    janaki
    wrote on last edited by
    #1

    @i have a structure as follows
    @
    @struct image_data
    @{
    int msgid;
    const char * fname;
    }@

    am assigning values to this structure as msgid =6 and fname = a.bmp
    then am sending the structure on udp to some other application on different machine
    and also am doing the qftp of this bmp file

    am able to get this file on other machine

    now my motto is to display the image file
    so what am doing is am displaying the fname which is filename of the image on the gui of other application.

    so when am displaying the structure data at the console am getting segmentation fault error
    when i have tried file name with the single char am getting the filename with single char at receiving end but when am trying with char * it is showing segmentation fault error

    am attaching the code here

    @
    @#include "GroundThread.h"

    struct Message
    {
    int message_id;
    }msg;

    struct img_file
    {
    int msg_id;
    const char* fname;
    }imgData;

    GroundThread::GroundThread(QObject *parent)
    :QThread(parent)
    {
    //restart = false;
    //abort = false;
    }
    GroundThread::~GroundThread()
    {

    }

    void GroundThread::run()
    {
    process_data();

    }
    void GroundThread::process_data()
    {
    std::cerr<<"am in thread"<<std::endl;
    //received_ftpData();
    Message msg;
    printf("Hello\n");
    int fd;

    printf("Hello2\n");
    struct sockaddr_in servaddr, cliaddr;

    void **status;

    fd = socket(AF_INET,SOCK_DGRAM,0);
    printf("Hello3\n");

    if(fd <0)
    cout<<"Socket creation Failed"<<endl;

    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = inet_addr("10.66.48.29"); //server ip addr
    servaddr.sin_port = htons(12000); //server poet no.
    printf("Hello4\n");
    if(bind(fd,(const struct sockaddr *)&servaddr,sizeof(servaddr))<0)
    cout<<"BIND FAILED"<<endl;
    unsigned char buffer[MAX_DATA_SIZE];

    socklen_t len=sizeof(cliaddr);

    fcntl(fd,F_SETFL,O_NONBLOCK);

    printf("Hello5\n");
    for(;;)

    {
    sleep(3);
    int n= recvfrom(fd,buffer,sizeof(buffer),0,(struct sockaddr *)&cliaddr,&len);

                      memcpy(&msg,buffer,sizeof(msg));
    

    printf("Hello7\n");
    cout<<"Received : bytes"<<n<<" "<<msg.message_id<<endl;
    if(msg.message_id ==6)
    {
    memcpy(&imgData,buffer,sizeof(imgData));
    cout<<"img msgid:"<<imgData.msg_id<<endl;
    cout<<"img filename:"<<imgData.fname<<endl;

    }

    if(n<1) continue;

    // emit received_data(buffer);

    // return NULL;

    }}@
    @

    please tell me how should i solve this

    thank u

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Please enclose your code with coding tags, otherwise it's really hard to read.

      Since you are using Qt, why not use QUdpSocket and Qt's container (i.e QByteArray) ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved