Segmentation fault while using real time connection with device.

  • Hi,
    I want to write a application which download data form device in real time.
    I writed library in c++ using cyusb_control_transfer() for comunicate with my device.
    When i use this library in console program all is working.
    But when i want to add it in window qt program it has problem with memory.

    I made window in .ui file with graphicsView and button.
    To button i add function:

    void Window::on_ButtonStart_clicked()

    Draw data function:

    void Window::drawDataOnScreen()
        m_chart = new QChart;
        m_chart->setMinimumSize(721, 301);
        m_chart->setMaximumSize(721, 301);
        QLineSeries *series = new QLineSeries;
        cyusb_handle *h;
        h = cyusb_gethandle(0);
        unsigned short len = packetLengthRegister(h);
        unsigned int *source = sourceFromPacket(h, len);
        for(int i=0; i<1; i++)
            series->append(0.001*i, source[i+54]);
        delete[] source;

    When i debug i get this:

    Signal from system: SIGSEGV
    Meaning of signal: Segmentation fault

    And it stop in first data transfer:

    unsigned char *databuff = new unsigned char[2];
    if(cyusb_control_transfer(h, 0x02, 0x04, 0, 0, databuff, 0, TIME_OUT))
            return 1;

    What i do worng?

  • @powp Hi,

    Probably cyusb_gethandle(0) returns null or not a valid pointer.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Where are you calling cyusb_control_transfer from ?

    Did you declare a cyusb_handle named h class member variable ?

    If so you are likely not initialising it and the one you have in drawDataOnScreen is not the same.

  • I don't know whats hapenned.
    I debug my program very cerrfully with much more traps and it starts works.
    I didn't change anything in my program.
    But thanks for help.

  • @powp if your issue is solved, please don't forget to mark your post as such. Thanks

Log in to reply

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