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. QT UDP SEND DOUBLE
Forum Updated to NodeBB v4.3 + New Features

QT UDP SEND DOUBLE

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.2k Views 2 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.
  • SurizerS Offline
    SurizerS Offline
    Surizer
    wrote on last edited by Surizer
    #1

    Hey guys i am new to QT , I am trying to send and receive datagram from simulink and QT. Successfully i was able to send variables from simulink to QT. Now am trying to send variables to simulink from QT. I am not sure how i am suppose to send a double variable from QT. It would be nice if someone can help me to send double type values .I have also attached the simulink side as a screenshot

    #include "myudp.h"
    double prev_a[3];
    
    MyUDP::MyUDP(QObject *parent) :
        QObject(parent)
        {
            socket = new QUdpSocket(this);
            socket->bind(QHostAddress::LocalHost, 25000);
            connect(socket, SIGNAL(readyRead()), this, SLOT(readyRead()));
        }
    /*    void MyUDP::HelloUDP() // instead of sending HelloUDP i want to send a double type variable.
        {
            QByteArray Data;
            Data.append("F");
    
            socket->writeDatagram(Data, QHostAddress::LocalHost, 26000);
        }
    */
    
    void MyUDP::readyRead()
    {
        double a[4];
    
        QByteArray buffer;
        buffer.resize(socket->pendingDatagramSize());
    
        QHostAddress sender;
        quint16 senderPort;
    
        socket->readDatagram(buffer.data(), buffer.size(),
                             &sender, &senderPort);
    
        memcpy(&a, buffer, 3*sizeof(double));
    
        if(a[0] != prev_a[0] || a[1] != prev_a[1] || a[2] != prev_a[2])
        {
            qDebug() << "\nMessage from: " << sender.toString();
            qDebug() << "Message port: " << senderPort;
            qDebug() << "X:" << a[0];
            qDebug() << "Y:" << a[1];
            qDebug() << "V:" << a[2];
        }
        else {
            qDebug() << "error";
    
        }
        prev_a[0] = a[0];
        prev_a[1] = a[1];
        prev_a[2] = a[2];
    
    }
    
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What about using QByteArray::number ?

      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
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved