Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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()
    {
        drawDataOnScreen();
    }
    

    Draw data function:

    void Window::drawDataOnScreen()
    {
        m_chart = new QChart;
        m_chart->setMinimumSize(721, 301);
        m_chart->setMaximumSize(721, 301);
        m_chart->legend()->hide();
    
        QLineSeries *series = new QLineSeries;
    
        cyusb_handle *h;
        h = cyusb_gethandle(0);
        globalResetAllDeviceRegister(h);
        switchONDevice(h);
    
        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;
    
        switchOFFDevice(h);
        globalResetAllDeviceRegister(h);
        closeDevices();
    
        m_chart->addSeries(series);
        m_chart->createDefaultAxes();
        m_chart->setAcceptHoverEvents(true);
    
        scene->addItem(m_chart);
    }
    

    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