Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. The program I created closes when data comes
Qt 6.11 is out! See what's new in the release blog

The program I created closes when data comes

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 561 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.
  • serkan_trS Offline
    serkan_trS Offline
    serkan_tr
    wrote on last edited by serkan_tr
    #1

    QT Version 5.15
    Platform Windows 10
    tools used CMake QT Creator
    1- The goal of the project: I created a class on the C++ side. i used qmlRegisterType to create object from this class on qml side. I have a variable on the C++ side and this variable is constantly updated. this variable I adjust the position of a circle with the data I receive, but the program closes after a certain point. Since there are so many files, I can only share the parts that I consider important.
    (is there an easier way ?)
    2-How can I send data from a C++ file to an object in QML without creating a new object?

    Seriallink.cpp

    JoyControl* joy_node;
    joy_node = new JoyControl;
    connect(this, &SerialLink::stateJoyChanged, joy_node, &JoyControl::setSerialData );
    .
    .
    .
    while(_port->bytesAvailable()){
            uint8_t cur_byte;
            _port->read((char*)&cur_byte, 1);
            // cur_byte = byte;
            if(state_ == 0){
                if(cur_byte == header_ &&  prev_byte == footer_){
                    rx_buffer[state_++] = cur_byte;
                }else{
                    state_ = 0;
                }
            }else if(state_ < HEADER_LEN + PAYLOAD_LEN){
                rx_buffer[state_++] = cur_byte;
            }else if(state_ < HEADER_LEN + PAYLOAD_LEN + FOOTER_LEN){
                state_ = 0;
                prev_byte = cur_byte;
                if(cur_byte == footer_){
                    joy_data[0] = static_cast<int16_t>(rx_buffer[1] & 0x01);
                    joy_data[1] = static_cast<int16_t>((rx_buffer[1]>>1) & 0x01);
                    joy_data[2] = static_cast<int16_t>((rx_buffer[1]>>2) & 0x01);
                    joy_data[3] = static_cast<int16_t>((rx_buffer[1]>>3) & 0x01);
                    joy_data[4] = static_cast<int16_t>((rx_buffer[1] >> 4) | ((rx_buffer[2] << 4) & 0x03FF));
                    joy_data[5] = static_cast<int16_t>((rx_buffer[2] >> 6) | ((rx_buffer[3] << 2) & 0x03FF));
                    joy_data[6] = static_cast<int16_t>((rx_buffer[4])      | ((rx_buffer[5] << 8) & 0x03FF));
                    joy_data[7] = static_cast<int16_t>((rx_buffer[5] >> 2) | ((rx_buffer[6] << 6) & 0x03FF));
                    joy_data[8] = static_cast<int16_t>((rx_buffer[6] >> 4) | ((rx_buffer[7] << 4) & 0x03FF));
                    joy_data[9] = static_cast<int16_t>((rx_buffer[7] >> 6) | ((rx_buffer[8] << 2) & 0x03FF));
                     emit stateJoyChanged(joy_data);
    

    roqml.cpp

    Q_PROPERTY(QVector<int> data READ data WRITE setData NOTIFY dataChanged)
    QVector<int> m_data = {0,0,0,0,0,0,0,0,0};
    Q_INVOKABLE void callbackSub(const joy_msg::SharedPtr msg);
    signals:
        void buttonChanged();
        void dataChanged();
    
    void RosQml::callbackSub(const joy_msg::SharedPtr msg){
       m_data[0] = msg->buttons[0];
       m_data[1] = msg->buttons[1];
       m_data[2] = msg->buttons[2];
       m_data[3] = msg->buttons[3];
       m_data[4] = msg->axes[0];
       m_data[5] = msg->axes[1];
       m_data[6] = msg->axes[2];
       m_data[7] = msg->axes[3];
       m_data[8] = msg->axes[4];
       m_data[9] = msg->axes[5];
       qDebug() << m_data[8];
       qDebug() << m_data[2];
    
       emit dataChanged();
    }
    

    qml

    import RosNode                      1.0
    
    Rosnode{
            id: ros
        }
        Slider {
            id:leftTopSlider
            from: 0
            to: 1023
    //        value: 0
            value:ros.data[7]
            anchors.top:backbutton.bottom
            anchors.topMargin:65
            anchors.left:backbutton.left
    }
            Rectangle{
                id:solJoy
                width: joyPointSize
                height:joyPointSize
                radius:joyPointSize
    //            anchors.centerIn:parent
    //            anchors.horizontalCenter: parent.horizontalCenter
    //            anchors.verticalCenter: parent.verticalCenter
                y: ros.data[8] //(ros.data[8]*175)/1023
                x:ros.data[6] //(ros.data[6]*175)/1023
    //            color:"#222222"
                color: "red"
            }
        }
    

    briefly the purpose of the codes is to communicate the data I get from the seriallink with Rosnode in the qml side and move the x and y positions of the slider and squares (slider works properly)

    I don't know exactly where I got the error. the program closes without error. Works fine when disconnecting on QML side

    jsulmJ 1 Reply Last reply
    0
    • serkan_trS serkan_tr

      QT Version 5.15
      Platform Windows 10
      tools used CMake QT Creator
      1- The goal of the project: I created a class on the C++ side. i used qmlRegisterType to create object from this class on qml side. I have a variable on the C++ side and this variable is constantly updated. this variable I adjust the position of a circle with the data I receive, but the program closes after a certain point. Since there are so many files, I can only share the parts that I consider important.
      (is there an easier way ?)
      2-How can I send data from a C++ file to an object in QML without creating a new object?

      Seriallink.cpp

      JoyControl* joy_node;
      joy_node = new JoyControl;
      connect(this, &SerialLink::stateJoyChanged, joy_node, &JoyControl::setSerialData );
      .
      .
      .
      while(_port->bytesAvailable()){
              uint8_t cur_byte;
              _port->read((char*)&cur_byte, 1);
              // cur_byte = byte;
              if(state_ == 0){
                  if(cur_byte == header_ &&  prev_byte == footer_){
                      rx_buffer[state_++] = cur_byte;
                  }else{
                      state_ = 0;
                  }
              }else if(state_ < HEADER_LEN + PAYLOAD_LEN){
                  rx_buffer[state_++] = cur_byte;
              }else if(state_ < HEADER_LEN + PAYLOAD_LEN + FOOTER_LEN){
                  state_ = 0;
                  prev_byte = cur_byte;
                  if(cur_byte == footer_){
                      joy_data[0] = static_cast<int16_t>(rx_buffer[1] & 0x01);
                      joy_data[1] = static_cast<int16_t>((rx_buffer[1]>>1) & 0x01);
                      joy_data[2] = static_cast<int16_t>((rx_buffer[1]>>2) & 0x01);
                      joy_data[3] = static_cast<int16_t>((rx_buffer[1]>>3) & 0x01);
                      joy_data[4] = static_cast<int16_t>((rx_buffer[1] >> 4) | ((rx_buffer[2] << 4) & 0x03FF));
                      joy_data[5] = static_cast<int16_t>((rx_buffer[2] >> 6) | ((rx_buffer[3] << 2) & 0x03FF));
                      joy_data[6] = static_cast<int16_t>((rx_buffer[4])      | ((rx_buffer[5] << 8) & 0x03FF));
                      joy_data[7] = static_cast<int16_t>((rx_buffer[5] >> 2) | ((rx_buffer[6] << 6) & 0x03FF));
                      joy_data[8] = static_cast<int16_t>((rx_buffer[6] >> 4) | ((rx_buffer[7] << 4) & 0x03FF));
                      joy_data[9] = static_cast<int16_t>((rx_buffer[7] >> 6) | ((rx_buffer[8] << 2) & 0x03FF));
                       emit stateJoyChanged(joy_data);
      

      roqml.cpp

      Q_PROPERTY(QVector<int> data READ data WRITE setData NOTIFY dataChanged)
      QVector<int> m_data = {0,0,0,0,0,0,0,0,0};
      Q_INVOKABLE void callbackSub(const joy_msg::SharedPtr msg);
      signals:
          void buttonChanged();
          void dataChanged();
      
      void RosQml::callbackSub(const joy_msg::SharedPtr msg){
         m_data[0] = msg->buttons[0];
         m_data[1] = msg->buttons[1];
         m_data[2] = msg->buttons[2];
         m_data[3] = msg->buttons[3];
         m_data[4] = msg->axes[0];
         m_data[5] = msg->axes[1];
         m_data[6] = msg->axes[2];
         m_data[7] = msg->axes[3];
         m_data[8] = msg->axes[4];
         m_data[9] = msg->axes[5];
         qDebug() << m_data[8];
         qDebug() << m_data[2];
      
         emit dataChanged();
      }
      

      qml

      import RosNode                      1.0
      
      Rosnode{
              id: ros
          }
          Slider {
              id:leftTopSlider
              from: 0
              to: 1023
      //        value: 0
              value:ros.data[7]
              anchors.top:backbutton.bottom
              anchors.topMargin:65
              anchors.left:backbutton.left
      }
              Rectangle{
                  id:solJoy
                  width: joyPointSize
                  height:joyPointSize
                  radius:joyPointSize
      //            anchors.centerIn:parent
      //            anchors.horizontalCenter: parent.horizontalCenter
      //            anchors.verticalCenter: parent.verticalCenter
                  y: ros.data[8] //(ros.data[8]*175)/1023
                  x:ros.data[6] //(ros.data[6]*175)/1023
      //            color:"#222222"
                  color: "red"
              }
          }
      

      briefly the purpose of the codes is to communicate the data I get from the seriallink with Rosnode in the qml side and move the x and y positions of the slider and squares (slider works properly)

      I don't know exactly where I got the error. the program closes without error. Works fine when disconnecting on QML side

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @serkan_tr Did you do any debugging?
      Where exactly in your code is the crash?
      And what kind of crash is that?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      serkan_trS 1 Reply Last reply
      0
      • jsulmJ jsulm

        @serkan_tr Did you do any debugging?
        Where exactly in your code is the crash?
        And what kind of crash is that?

        serkan_trS Offline
        serkan_trS Offline
        serkan_tr
        wrote on last edited by
        #3

        @jsulm Debug mode does not work properly file too many close to 1000 files. In addition, since I am using ROS, it does not work in Debug mode, I have to do it in release mode. it doesn't give any error message it just says ".exe crashed" and closes

        jsulmJ 1 Reply Last reply
        0
        • serkan_trS serkan_tr

          @jsulm Debug mode does not work properly file too many close to 1000 files. In addition, since I am using ROS, it does not work in Debug mode, I have to do it in release mode. it doesn't give any error message it just says ".exe crashed" and closes

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @serkan_tr If debugging really does not work you could at least add debug output (qDebug) to your code to locate the place where it is crashing.

          But I think I know what the problem is: m_data has 9 elements but you're trying to assign something at position 10: m_data[9] = msg->axes[5];

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          serkan_trS 2 Replies Last reply
          2
          • jsulmJ jsulm

            @serkan_tr If debugging really does not work you could at least add debug output (qDebug) to your code to locate the place where it is crashing.

            But I think I know what the problem is: m_data has 9 elements but you're trying to assign something at position 10: m_data[9] = msg->axes[5];

            serkan_trS Offline
            serkan_trS Offline
            serkan_tr
            wrote on last edited by
            #5

            @jsulm many thanks

            1 Reply Last reply
            0
            • serkan_trS serkan_tr has marked this topic as solved on
            • jsulmJ jsulm

              @serkan_tr If debugging really does not work you could at least add debug output (qDebug) to your code to locate the place where it is crashing.

              But I think I know what the problem is: m_data has 9 elements but you're trying to assign something at position 10: m_data[9] = msg->axes[5];

              serkan_trS Offline
              serkan_trS Offline
              serkan_tr
              wrote on last edited by
              #6

              @jsulm So do I have a chance to make it easier to use? In the project, I send the values ​​from the serialqml.cpp file with the help of ROS and receive it with rosqml.cpp and send it to the qml file.With qml, serialqml.cpp and qml file are in the same place. Can I directly link the values ​​from serialqml.cpp to this qml file or do I have to link it with the c++ side?

              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