Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Segmentation fault while using real time connection with device.

    General and Desktop
    4
    5
    376
    Loading More Posts
    • 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.
    • P
      powp last edited by

      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?

      Gojir4 1 Reply Last reply Reply Quote 0
      • Gojir4
        Gojir4 @powp last edited by

        @powp Hi,

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

        1 Reply Last reply Reply Quote 0
        • SGaist
          SGaist Lifetime Qt Champion last edited by

          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.

          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 Reply Quote 0
          • P
            powp last edited by

            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.

            Pablo J. Rogina 1 Reply Last reply Reply Quote 0
            • Pablo J. Rogina
              Pablo J. Rogina @powp last edited by

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

              Upvote the answer(s) that helped you solve the issue
              Use "Topic Tools" button to mark your post as Solved
              Add screenshots via postimage.org
              Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

              1 Reply Last reply Reply Quote 0
              • First post
                Last post