Quantcast
Channel: Active questions tagged qtquick2 - Stack Overflow
Viewing all articles
Browse latest Browse all 107

Data sent from CPP causes interface crash in QML

$
0
0

first of all, I have a problem like this. I want to transfer the data to the QML side with a signal from C ++, but after a while my interface crashes without giving any error. I can't find the reason for this, I can't see it even though I debug, is there any error in my code?NOTE: I didn't add unnecessary parts of the codeNOTE2: QT 5.15.16

QML:

Window { QtObject {    id: tcpVariables    property real tcp_velocity_X_Angle: 0}   Connections {            target: tcpClient             function onVelocity_X_Changed() {               var newVelocity = tcpClient.get_Velocity_X()               if (!isNaN(newVelocity) && isFinite(newVelocity)) {                       tcpVariables.tcp_velocity_X_Angle = newVelocity;                         console.log("tcp_velocity_X_Angle signal triggered: " + tcpVariables.tcp_velocity_X_Angle);               } else {                    console.error("Invalid velocity value: " + newVelocity);               }           }        }}

tcpClient HEADER

tcpClient.h:class TcpClient : public QObject{    Q_OBJECTpublic:    Q_PROPERTY(qreal float_X_velocity READ get_Velocity_X WRITE setVelocity_X NOTIFY velocity_X_Changed)    QML_ELEMENTpublic:    Q_INVOKABLE qreal get_Velocity_X() const {return float_X_velocity; }     void  setVelocity_X (qreal value);    qreal float_X_velocity; /**/signals:    void velocity_X_Changed();

TcpClient CPP USAGE VARIABLE

tcpClient.cpp ( CODE USAGE ): qint32 x_velocity_int = (static_cast<qint32>(data[29]) << 24) |                                                (static_cast<qint32>(data[28]) << 16) |                                                (static_cast<qint32>(data[27]) << 8) |                                                (static_cast<qint32>(data[26]) & 0xff);float float_X_velocity;std::memcpy(&float_X_velocity, &x_velocity_int, sizeof(float));   setVelocity_X(static_cast<qreal>(float_X_velocity));

TcpClient CPP USAGE FUNCTION

tcpClient.cpp: (FUNCTION)void TcpClient::setVelocity_X(qreal value) {    if (!qFuzzyCompare(float_X_velocity, value)) {        if (qIsNaN(value) || !qIsFinite(value)) {            qWarning() << "Invalid velocity value: " << value;            return; // Geçersiz değeri atama        }        float_X_velocity = value;        emit velocity_X_Changed();        qDebug() << "float_X_velocity signal emitted, new value: " << float_X_velocity;    }}

MAIN.CPP USAGE

main.cpp:int main(int argc, char *argv[]){    QGuiApplication app(argc, argv);    // OpenGL USAGE    QCoreApplication::setAttribute(Qt::AA_UseOpenGLES);  // TCP OBJECTS    TcpClient tcpclient;    // UI OBJECTS    QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("tcpClient", &tcpclient);  const QUrl url(QStringLiteral("../qml/Screens/splashScreen.qml"));    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,&app, [url](QObject *obj, const QUrl &objUrl) {         if (!obj && url == objUrl)             QCoreApplication::exit(-1);     }, Qt::QueuedConnection);    engine.load(url);    videoStreamer.startCapture();    return app.exec();}

Viewing all articles
Browse latest Browse all 107

Trending Articles