Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-129177

QDataStream does not work with std::[u]int64_t

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • 5.15.17, 6.8.0 Beta4
    • Core: I/O, Core: Other
    • None
    • Debian 12 amd64
      gcc (Debian 10.2.1-6) 10.2.1 20210110
       (C++17, C++20 mode)
    • Linux/X11

    Description

      If we want to use std::x64_t types for parsing binary data using QDataStream, and then put values it into QVariant for whatever reason, we get compilation error for using std::int64_t or std::uint64_t:

      error: ambiguous overload foroperator<<’ (operand types are ‘QDataStream’ and ‘int64_t’ {aka ‘long int’}) 
      error: ambiguous overload foroperator<<’ (operand types are ‘QDataStream’ and ‘uint64_t’ {aka ‘long unsigned int’})
      
      error: no match foroperator>>’ (operand types are ‘QDataStream’ and ‘int64_t’ {aka ‘long int’}) 
      error: no match foroperator>>’ (operand types are ‘QDataStream’ and ‘uint64_t’ {aka ‘long unsigned int’})
      

       

      error: call of overloaded ‘QVariant(<brace-enclosed initializer list>)’ is ambiguous 

      Code example:

      #include <QByteArray>
      #include <QDataStream>
      #include <QDebug>
      #include <QIODevice>
      #include <QVariant>
      
      int main()
      {
          QByteArray buffer;
          QDataStream ds{&buffer, QIODevice::ReadWrite};
      
          ds << std::int8_t{1};
          ds << std::int16_t{2};
          ds << std::int32_t{3};
          ds << std::int64_t{4};
      
          ds << std::uint8_t{10};
          ds << std::uint16_t{11};
          ds << std::uint32_t{12};
          ds << std::uint64_t{13};
      
          std::int8_t a;
          std::int16_t b;
          std::int32_t c;
          std::int64_t d;
      
          std::uint8_t a2;
          std::uint16_t b2;
          std::uint32_t c2;
          std::uint64_t d2;
      
          ds.device()->seek(0);
      
          ds >> a;
          ds >> b;
          ds >> c;
          ds >> d;
      
          ds >> a2;
          ds >> b2;
          ds >> c2;
          ds >> d2;
      
          qDebug() << QVariant{a};
          qDebug() << QVariant{b};
          qDebug() << QVariant{c};
          qDebug() << QVariant{d};
      
          qDebug() << QVariant{a2};
          qDebug() << QVariant{b2};
          qDebug() << QVariant{c2};
          qDebug() << QVariant{d2};
      }
      
       

      I see no reason why this inconsistency should exist, as it works fine with 8/16/32_t.

       

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              thiago Thiago Macieira
              vdargis_at_uab_styritrade Vincas Dargis
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes