Rami Shawwa
Rami Shawwa

Reputation: 53

whats wrong in my code? why the error msg

The following code works just fine I can get the results I want if I ignore the error message once I run it. the error I get is: Debug Error! Program:c:\qt\qt5.5.1\5.5\msvc2013_64\bin\Qt5Cored.dll Module: 5.5.1 File: global\qglobal.cpp Line: 2966 .....

if I chose to ignore error the console app displays all data correctly it shows the correct bits array it also shows correct character for the binary array and last it gives also the correct byte decimal value for the byte char...

this is the error in console: ASSERT: "uint(i) < uint(size())" in file c:\work\build\qt5_workdir\w\s\qtbase\sr c\corelib\tools\qbytearray.h, line 464

this is correct output:

Bits are: QBitArray(0110 0011)

Byte Char is "c"

Decimal format Bytes are: 99

Code used:

    QBitArray Alphabits(8);
    Alphabits[0] = false;
    Alphabits[1] = true;
    Alphabits[2] = true;
    Alphabits[3] = false;
    Alphabits[4] = false;
    Alphabits[5] = false;
    Alphabits[6] = true;
    Alphabits[7] = true;

    QByteArray Alphabytes;
    // Convert from QBitArray to QByteArray
    for(int b=0; b<Alphabits.count();++b) {
        Alphabytes[b/8] = (Alphabytes.at(b/8) | ((Alphabits[b]?1:0)<<(7-(b%8))));
    }

    qDebug() << "Bits are:" << Alphabits;
    qDebug() << "Byte Char is" << Alphabytes;
    qDebug() << "Decimal format Bytes are: "<< static_cast<quint8>(Alphabytes[0]);

Upvotes: 0

Views: 768

Answers (2)

Evgeny
Evgeny

Reputation: 4010

Ok, i figure out where is the problem. This is because when you inside for make call Alphabytes.at(b/8) for the first time, the size of Alphabytes is zero, so you try get index that is out of array range. Replace this with Alphabytes[b/8] = (Alphabytes[b/8] |.......

Upvotes: 2

Rami Shawwa
Rami Shawwa

Reputation: 53

It seems that in release mode everything compiles and even no errors or warnings etc are detected so this is strange it only happens in debug mode so I think ill report this in QT bug tracking maybe... Unless anyone can figure out why this error only happens when debugging...

Upvotes: 0

Related Questions