[solved] 'invalid conversion' issue



  • 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



  • 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.



  • Works a treat! Thanks :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.