Seeking Help on Debugging QIODevice Issue
-
Perhaps a long shot, but I need some hits to help debugging a QIODevice issue that I experience. I am using the OPC Package component of QtOfficeOpenXml. The QtOfficeOpenXml::Opc::PackagePart returns a QIODevice when calling getDevice(). I need to process the content of this QIODevice by another library that requires using a concrete file. Hence, I copy the content of the QIODevice to a QTemporaryFile with the following code, where Device is the QIODevice of originating from calling QtOfficeOpenXml::Opc::PackagePart::getDevice()
QDataStream InStream(Device); TempFile = new QTemporaryFile(); TempFile->open(); QString TempName = TempFile->fileName(); QDataStream OutStream(TempFile); const int BlockSize = 1024; char Block[BlockSize]; int Length = 0; while ((Length = InStream.readRawData(Block, BlockSize)) > 0) OutStream.writeRawData(Block, Length); TempFile->flush(); TempFile->close();
The above code does work in most cases, but in some cases, I experience that QDataStream::readRawData returns a Length of 0, while the content is really not empty. I have added some tests such as checking with atEnd and using seek(0) to make sure the read pointer is at the beginning, but all that doesn't show signs of identifying a problem that would cause QDataStream::readRawData to return a Length of 0. Would anyone have more hits on how I could debug the problem further? Is there perhaps a way to inspect the content of the QIODevice in QtCreator's Debugger view? Any suggestions are appreciated :)
-
@ModelTech Did you print https://doc.qt.io/qt-6/qiodevice.html#errorString before using Device?
There are also: -
@jsulm Thanks for those ideas :)
I have tried the following:
bool Test1 = Device->isOpen(); bool Test2 = Device->isReadable(); bool Test3 = Device->atEnd(); bool Test4 = Device->isSequential(); qint64 Test5 = Device->pos(); QString Test6 = Device->errorString();
In both cases (i.e., where the first evaluation of Length in the condition of the while loop is larger than 0 and equal to 0, while it should be larger than 0 in both cases), I got:
Test1 -> true Test2 -> true Test3 -> false Test4 -> false Test5 -> 0; Test6 -> "Unknown Error"
-
Ok. After trying lots of things, I found a bypass to the problem by using the QtOfficeOpenXml library in a slightly different way...
-