Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. The Actual Data not received in receiver slot while using QByteArray
Forum Updated to NodeBB v4.3 + New Features

The Actual Data not received in receiver slot while using QByteArray

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
7 Posts 3 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.
  • V Offline
    V Offline
    vivekyuvan
    wrote on last edited by vivekyuvan
    #1

    Hi Friends
    I have a problem with using QByteArray , The receiver slot can not receive actual data

    Here is the code snippet

    Sending Slot is :

    void My_SIGNAL_GET_Form1::Test_Array_Initialization_1()
    {
       QByteArray m_data_1("\x0c\x06\x04\x04\x02\x00",6);
       emit Send_Data_Array_to_form(m_data_1);     //Emiting data to 
      qDebug()<<"Sending_DAta:"<<m_data_1<<endl;
    }
    

    I formed connect signal like this in my My_SIGNAL_GET_Form1.cpp

    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(Test_Array_Initialization_1()));
    

    The receiver slot in main window

    void MainWindow::Test_Array_Initialization(QByteArray m_data)
    {
        qDebug()<<"*****SIGNAL EMITED From My_signal_get_form1**********"<<endl;
    
      qDebug()<<"data received"<<m_data<<endl;
    
    }
    

    I formed connect signal like this mainwindow.cpp

    connect(my_form1,SIGNAL(Send_Data_Array_to_form(QByteArray)),this,SLOT(Test_Array_Initialization(QByteArray)));
    

    0_1506059741193_Console.png

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      I strongly recommend using the new signal-slot syntax, it will warn you about connection problems at compile time.

      In the picture you attach, we can clearly see "data received" line, so it seems to be working. What exactly do you expect to happen, what is wrong?

      (Z(:^

      1 Reply Last reply
      2
      • V Offline
        V Offline
        vivekyuvan
        wrote on last edited by vivekyuvan
        #3

        hi@sierdzio If i send char in QByte array thats fine to receive. but I want to emit integer or hexadecimal value in emit signal. I really don know how to do this? help me out to resolve this issue.

        this data received properly in receiver slot

        QByteArray m_data_1("\A\F\B\E\C\D",6);
        

        But I want to send Hexdecimal data like

        QByteArray m_data_1("\x0c\x06\x04\x04\x02\x00",6);
        or
        QByteArray m_data_1("\0\4\7\9\5\3",6);
        

        if i send hexadecimal value or integer value in emit signal the receiver slot i cant see the actual data and it shows a junk data.

        data received "
        Sending_DAta: "
        
        J.HilkJ 1 Reply Last reply
        0
        • sierdzioS Offline
          sierdzioS Offline
          sierdzio
          Moderators
          wrote on last edited by
          #4

          Most probably what you see is the way that your console interprets the data (it displays UTF-8, most probably, so your bytes are reinterpreted as UTF-8 text). The underlying QByteArray is fine and sends exactly what you want.

          In your qDebug() statements, add .toHex() to the byte array, like so:

           qDebug()<<"data received"<<m_data.toHex();
          

          Also, don't use endl, it is not needed in qDebug. And another hint: you don't need to provide data size to QByteArray, it will automatically calculate it. So, there is no need to specify the second parameter in QByteArray constructor.

          (Z(:^

          V 1 Reply Last reply
          2
          • V vivekyuvan

            hi@sierdzio If i send char in QByte array thats fine to receive. but I want to emit integer or hexadecimal value in emit signal. I really don know how to do this? help me out to resolve this issue.

            this data received properly in receiver slot

            QByteArray m_data_1("\A\F\B\E\C\D",6);
            

            But I want to send Hexdecimal data like

            QByteArray m_data_1("\x0c\x06\x04\x04\x02\x00",6);
            or
            QByteArray m_data_1("\0\4\7\9\5\3",6);
            

            if i send hexadecimal value or integer value in emit signal the receiver slot i cant see the actual data and it shows a junk data.

            data received "
            Sending_DAta: "
            
            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by J.Hilk
            #5

            @vivekyuvan thats qDebug() "fault" not that of QByteArray
            try toHex()

            qDebug()<<"data received"<<m_data.toHex()<<endl;
            
            

            edit: @sierdzio was a tiny bit faster x)


            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            V 1 Reply Last reply
            2
            • sierdzioS sierdzio

              Most probably what you see is the way that your console interprets the data (it displays UTF-8, most probably, so your bytes are reinterpreted as UTF-8 text). The underlying QByteArray is fine and sends exactly what you want.

              In your qDebug() statements, add .toHex() to the byte array, like so:

               qDebug()<<"data received"<<m_data.toHex();
              

              Also, don't use endl, it is not needed in qDebug. And another hint: you don't need to provide data size to QByteArray, it will automatically calculate it. So, there is no need to specify the second parameter in QByteArray constructor.

              V Offline
              V Offline
              vivekyuvan
              wrote on last edited by
              #6

              @sierdzio The problem solved thanks for the reply.

              1 Reply Last reply
              1
              • J.HilkJ J.Hilk

                @vivekyuvan thats qDebug() "fault" not that of QByteArray
                try toHex()

                qDebug()<<"data received"<<m_data.toHex()<<endl;
                
                

                edit: @sierdzio was a tiny bit faster x)

                V Offline
                V Offline
                vivekyuvan
                wrote on last edited by
                #7

                @J.Hilk The problem is solved Thanks for the reply

                1 Reply Last reply
                1

                • Login

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