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. type qualifiers ignored
Qt 6.11 is out! See what's new in the release blog

type qualifiers ignored

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 7 Posters 4.3k 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.
  • dheerendraD dheerendra

    What is the data type of response.data ?

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by
    #3

    Hi
    response.data is unsigned char data[260];
    :)
    so issue/warning is unsigned char vs char and
    it warns that the cast -removes/ignores the sign.

    So the big question is about the data.
    If it contains negative values, then cast might alter data.
    if not, should be fine.

    1 Reply Last reply
    1
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
      wrote on last edited by
      #4

      @mrjj It was miss from my side which is exactly at the the top :)

      Dheerendra
      @Community Service
      Certified Qt Specialist
      https://www.pthinks.com

      mrjjM 1 Reply Last reply
      0
      • dheerendraD dheerendra

        @mrjj It was miss from my side which is exactly at the the top :)

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #5

        @dheerendra
        Funny enough, i also didn't see that line first time i read post. :)

        1 Reply Last reply
        0
        • C ckvsoft

          Hi

          I got a "Warnung: type qualifiers ignored on cast result type [-Wignored-qualifiers]"

          response.data is unsigned char data[260];
          
          QByteArray ba;
                  Response response = signHash(pin, hash);
                   
                  for (uint i = 0; i < response.length; i++)
                     ba[i] = (const char)response.data[i];
          

          Can i simply remove "(const char)" for same result?

          lg Chris

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by aha_1980
          #6

          @ckvsoft I think the problem is the const, try to remove it, it serves no purpose here.

          
          So either use `append` or search a suitable constructor for ` ba`, like http://doc.qt.io/qt-5/qbytearray.html#QByteArray-1
          
          In that case, you have to `reinterpret_cast< const char *>`

          Qt has to stay free or it will die.

          J.HilkJ 1 Reply Last reply
          1
          • aha_1980A aha_1980

            @ckvsoft I think the problem is the const, try to remove it, it serves no purpose here.

            
            So either use `append` or search a suitable constructor for ` ba`, like http://doc.qt.io/qt-5/qbytearray.html#QByteArray-1
            
            In that case, you have to `reinterpret_cast< const char *>`
            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #7

            @aha_1980 said in type qualifiers ignored:

            But: this code will crash as ba initially has size zero, so accessing bytes with [] is undefined behavior.

            it actually won‘t QByeArray atomatically resizes when you try to access it outside it bounds. It‘s slow, but it won‘t crash.


            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.

            aha_1980A C 2 Replies Last reply
            2
            • J.HilkJ J.Hilk

              @aha_1980 said in type qualifiers ignored:

              But: this code will crash as ba initially has size zero, so accessing bytes with [] is undefined behavior.

              it actually won‘t QByeArray atomatically resizes when you try to access it outside it bounds. It‘s slow, but it won‘t crash.

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @J.Hilk ok, that was new for me - will try it.

              It's interesting as other Qt containers dont work that way...

              Qt has to stay free or it will die.

              Christian EhrlicherC 1 Reply Last reply
              0
              • aha_1980A aha_1980

                @J.Hilk ok, that was new for me - will try it.

                It's interesting as other Qt containers dont work that way...

                Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #9

                @aha_1980 said in type qualifiers ignored:

                It's interesting as other Qt containers dont work that way...

                'interesting' is imo not the correct word here... it's strange. It's similar to the QContainer::value() functions. :/

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

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

                  @aha_1980 said in type qualifiers ignored:

                  But: this code will crash as ba initially has size zero, so accessing bytes with [] is undefined behavior.

                  it actually won‘t QByeArray atomatically resizes when you try to access it outside it bounds. It‘s slow, but it won‘t crash.

                  C Offline
                  C Offline
                  ckvsoft
                  wrote on last edited by
                  #10

                  @J.Hilk right. It wont't crash. But i fix this now ;-)

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    ckvsoft
                    wrote on last edited by ckvsoft
                    #11

                    Hi

                    I think it was fixed. I need the QByteArray as Base64 and not the int value;
                    QByteArray doesn't specify either signed or unsigned so

                                char ch;
                                unsigned char uch;
                    
                                ch=231;
                                uch=(char) ch;
                                QByteArray ba1, ba2;
                                ba1[0] = ch;
                                ba2[0] = uch;
                    
                                qDebug() << (int)ch << "/"<< (int)uch;
                                qDebug() << ba1 << "/"<< ba2;
                                qDebug() << (signed char)ba1[0] << "/"<< (unsigned char)ba1[0];
                                qDebug() << (signed char)ba2[0] << "/"<< (unsigned char)ba2[0];
                    
                                QVERIFY(ba1.toBase64() == ba2.toBase64());
                    

                    QDEBUG : QRK::testBA() -25 / 231
                    QDEBUG : QRK::testBA() "\xE7" / "\xE7"
                    QDEBUG : QRK::testBA() -25 / 231
                    QDEBUG : QRK::testBA() -25 / 231

                    QVERYFY pass true;

                    So i can remove (const char)
                    lg Chris

                    jsulmJ 1 Reply Last reply
                    1
                    • C ckvsoft

                      Hi

                      I think it was fixed. I need the QByteArray as Base64 and not the int value;
                      QByteArray doesn't specify either signed or unsigned so

                                  char ch;
                                  unsigned char uch;
                      
                                  ch=231;
                                  uch=(char) ch;
                                  QByteArray ba1, ba2;
                                  ba1[0] = ch;
                                  ba2[0] = uch;
                      
                                  qDebug() << (int)ch << "/"<< (int)uch;
                                  qDebug() << ba1 << "/"<< ba2;
                                  qDebug() << (signed char)ba1[0] << "/"<< (unsigned char)ba1[0];
                                  qDebug() << (signed char)ba2[0] << "/"<< (unsigned char)ba2[0];
                      
                                  QVERIFY(ba1.toBase64() == ba2.toBase64());
                      

                      QDEBUG : QRK::testBA() -25 / 231
                      QDEBUG : QRK::testBA() "\xE7" / "\xE7"
                      QDEBUG : QRK::testBA() -25 / 231
                      QDEBUG : QRK::testBA() -25 / 231

                      QVERYFY pass true;

                      So i can remove (const char)
                      lg Chris

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @ckvsoft said in type qualifiers ignored:

                      (char)

                      Just a note: you should avoid C style casts in C++ and use C++ type casts (like static_cast) instead.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      3

                      • Login

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