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. About QByteArray
Forum Updated to NodeBB v4.3 + New Features

About QByteArray

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 331 Views
  • 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.
  • taku-sT Offline
    taku-sT Offline
    taku-s
    wrote on last edited by
    #1

    Hello, everyone.
    I'm using Qt 5.15.1 + MSVC2019 32bit.
    I have a few questions.
    When I compile the following code

    There's a warning on line 22.
    C4309: 'conversion': truncation of constant value

    I think the BYTE range is 256, why?

    There is an error on line 23.
    call to member function 'append' is ambiguous
    candidate function

    On line 15, it's not a problem, so why is it?

    Best regards, thank you.

    1	#include <Windows.h>
    2	
    3	void MainWindow::on_pushButton_clicked()
    4	{
    5	    BYTE data[5];
    6	    data[0] = 0x08;
    7	    data[1] = 0x86;
    8	    data[2] = 0x00;
    9	    data[3] = 0x41;
    10	    data[4] = 0x53;
    11
    12	    QByteArray Byt;
    13
    14	    for(int i=0; i<5; i++){
    15	        Byt.append(data[i]);
    16	    }
    17
    18	    ui->lineEdit->setText(Byt.toHex(' '));
    19
    20	    Byt.clear();
    21	    Byt.append(0x08);
    22	    Byt.append(0x86);
    23	    Byt.append(0x00);						call to member function 'append' in ambiguous
    24	    Byt.append(0x41);
    25	    Byt.append(0x53);
    26
    27	    ui->lineEdit_2->setText(Byt.toHex(' '));
    28	}
    
    JonBJ 1 Reply Last reply
    0
    • taku-sT taku-s

      Hello, everyone.
      I'm using Qt 5.15.1 + MSVC2019 32bit.
      I have a few questions.
      When I compile the following code

      There's a warning on line 22.
      C4309: 'conversion': truncation of constant value

      I think the BYTE range is 256, why?

      There is an error on line 23.
      call to member function 'append' is ambiguous
      candidate function

      On line 15, it's not a problem, so why is it?

      Best regards, thank you.

      1	#include <Windows.h>
      2	
      3	void MainWindow::on_pushButton_clicked()
      4	{
      5	    BYTE data[5];
      6	    data[0] = 0x08;
      7	    data[1] = 0x86;
      8	    data[2] = 0x00;
      9	    data[3] = 0x41;
      10	    data[4] = 0x53;
      11
      12	    QByteArray Byt;
      13
      14	    for(int i=0; i<5; i++){
      15	        Byt.append(data[i]);
      16	    }
      17
      18	    ui->lineEdit->setText(Byt.toHex(' '));
      19
      20	    Byt.clear();
      21	    Byt.append(0x08);
      22	    Byt.append(0x86);
      23	    Byt.append(0x00);						call to member function 'append' in ambiguous
      24	    Byt.append(0x41);
      25	    Byt.append(0x53);
      26
      27	    ui->lineEdit_2->setText(Byt.toHex(' '));
      28	}
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @taku-s said in About QByteArray:
      BYTE is probably unsigned char, or similar. In lines 21--25 you are passing literal numbers, which are ints.

      The warning on #22 is doubtless because Byt.append(0x86); has its top bit set/negative value? At a guess, the "ambiguous" Byt.append(0x00); is because with value 0 it could be a pointer and it doesn't know between QByteArray &QByteArray::append(char ch) and QByteArray &QByteArray::append(const char *str)?

      Make your constant values chars, like char(0x08) or unsigned char(0x08), or as character constants like '\x08'.

      1 Reply Last reply
      1
      • taku-sT Offline
        taku-sT Offline
        taku-s
        wrote on last edited by
        #3

        Thank you for explaining this in detail.
        I've managed to understand it.

        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