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. QByteArray toInt doesnt work
Qt 6.11 is out! See what's new in the release blog

QByteArray toInt doesnt work

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 704 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.
  • B Offline
    B Offline
    BartoszT
    wrote on last edited by BartoszT
    #1

    There is my code under debug.
    0_1563371213594_prog.png

    Conversion to int doesn't work. I get 0 in the current_time variable but the conversion result is success (ok=0)
    Compilation is correct.
    Any sugestion?

    K JonBJ 2 Replies Last reply
    0
    • B BartoszT

      There is my code under debug.
      0_1563371213594_prog.png

      Conversion to int doesn't work. I get 0 in the current_time variable but the conversion result is success (ok=0)
      Compilation is correct.
      Any sugestion?

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @BartoszT

      What is CurrentDateTime?
      Is this based on QDateTime?
      If yes, you cannot simply convert it to int.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      4
      • B BartoszT

        There is my code under debug.
        0_1563371213594_prog.png

        Conversion to int doesn't work. I get 0 in the current_time variable but the conversion result is success (ok=0)
        Compilation is correct.
        Any sugestion?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @BartoszT
        Naturally we can assume QByteArray::toInt() does work, else there would be a whole lot of problems & complaints.

        In what way is your QByteArray CurrentDataTime contents related to the number of seconds (since 1970) argument in QDateTime::fromTime_t(uint seconds)? (And while I think of it, are you compiling for 32-, not 64-bit?)

        1 Reply Last reply
        2
        • B Offline
          B Offline
          BartoszT
          wrote on last edited by BartoszT
          #4

          0_1563396794707_prog.png
          and has 4 bytes - it is 32bit time.

          ... but now i see that ok get a false as a result of conversion toInt.
          So, why toInt doesnt watn to work whit this 4byte QByteArray?

          JKSHJ 1 Reply Last reply
          0
          • B BartoszT

            0_1563396794707_prog.png
            and has 4 bytes - it is 32bit time.

            ... but now i see that ok get a false as a result of conversion toInt.
            So, why toInt doesnt watn to work whit this 4byte QByteArray?

            JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by VRonin
            #5

            @BartoszT said in QByteArray toInt doesnt work:

            So, why toInt doesnt watn to work whit this 4byte QByteArray?

            Because your byte array does not contain ASCII text that represents an integer. See https://doc.qt.io/qt-5/qbytearray.html#toInt for an example on how to use QByteArray::toInt().

            If you want to interpret 4 bytes as a 32-bit integer, use a reinterpret_cast:

            int i = *reinterpret_cast<const int*>(myArray.constData());

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            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