Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [solved] 'invalid conversion' issue

    C++ Gurus
    2
    3
    1093
    Loading More Posts
    • 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.
    • McLion
      McLion last edited by

      Hi,
      I am having a 'invalid conversion' that I don't understand:

      Function:
      @void LongToAsciiQbArrayLeadZ(QByteArray * cAscii, ulong lLongVal, char cNbr)
      {
      while(cNbr--)
      {
      cAscii[cNbr] = (char)((lLongVal ) + '0');
      lLongVal /= 10;
      }
      }
      @

      Call:
      @QByteArray qbTempArray;
      LongToAsciiQbArrayLeadZ(&qbTempArray, uLogCounter.l++, 10);@

      leads to:
      Warnung:array subscript has type 'char'
      Fehler:invalid conversion from 'char' to 'const char*'

      I just don't get what's wrong?
      Same works in native C with char array instead of QByteArray.
      Thanks, McL

      1 Reply Last reply Reply Quote 0
      • M
        mcosta last edited by

        Hi,

        try modifying the code like this
        @
        void LongToAsciiQbArrayLeadZ(QByteArray &cAscii, ulong lLongVal, char cNbr)
        {
        while(cNbr--)
        {
        cAscii[cNbr] = (char)((lLongVal ) + '0');
        lLongVal /= 10;
        }
        }
        @

        @
        QByteArray qbTempArray;
        LongToAsciiQbArrayLeadZ(qbTempArray, uLogCounter.l++, 10);
        @

        You used a QByteArray pointer.

        Once your problem is solved don't forget to:

        • Mark the thread as SOLVED using the Topic Tool menu
        • Vote up the answer(s) that helped you to solve the issue

        You can embed images using (http://imgur.com/) or (http://postimage.org/)

        1 Reply Last reply Reply Quote 0
        • McLion
          McLion last edited by

          Works a treat! Thanks :)

          1 Reply Last reply Reply Quote 0
          • First post
            Last post