The program I created closes when data comes
-
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
-
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
@serkan_tr Did you do any debugging?
Where exactly in your code is the crash?
And what kind of crash is that? -
@serkan_tr Did you do any debugging?
Where exactly in your code is the crash?
And what kind of crash is that? -
@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
@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_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];
-
S serkan_tr has marked this topic as solved on
-
@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];
@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?