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. Seeking Help on Debugging QIODevice Issue

Seeking Help on Debugging QIODevice Issue

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 441 Views 1 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.
  • ModelTechM Offline
    ModelTechM Offline
    ModelTech
    wrote on last edited by
    #1

    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 :)

    jsulmJ 1 Reply Last reply
    0
    • ModelTechM ModelTech

      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 :)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @ModelTech Did you print https://doc.qt.io/qt-6/qiodevice.html#errorString before using Device?
      There are also:

      • https://doc.qt.io/qt-6/qiodevice.html#isOpen
      • https://doc.qt.io/qt-6/qiodevice.html#isReadable

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      ModelTechM 1 Reply Last reply
      1
      • jsulmJ jsulm

        @ModelTech Did you print https://doc.qt.io/qt-6/qiodevice.html#errorString before using Device?
        There are also:

        • https://doc.qt.io/qt-6/qiodevice.html#isOpen
        • https://doc.qt.io/qt-6/qiodevice.html#isReadable
        ModelTechM Offline
        ModelTechM Offline
        ModelTech
        wrote on last edited by ModelTech
        #3

        @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"
        
        1 Reply Last reply
        0
        • ModelTechM Offline
          ModelTechM Offline
          ModelTech
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0
          • ModelTechM Offline
            ModelTechM Offline
            ModelTech
            wrote on last edited by
            #5

            Ok. After trying lots of things, I found a bypass to the problem by using the QtOfficeOpenXml library in a slightly different way...

            1 Reply Last reply
            0
            • ModelTechM ModelTech has marked this topic as solved on

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved