0

Please describe what the "I/O Possible" SIGIO error typically indicates, from a QT C++ prospective. I know I/O stands for Input/output, but that's about all I know. The only decent information I have found is: http://davmac.org/davpage/linux/async-io.html but it is too generic to help me with my problem.

I don't necessarily need an answer telling me exactly what I did wrong (below), but hope to get a more informative answer on what activities generally lead to this error and what it indicates your doing wrong.


The remaining section will give you an idea on the activities I am doing, but your answer need to be specific to this section (my code) at all and can just describe what the error indicates and any specific QT information related to it

I am receiving this error sometimes on first loop and other times after 5 loops or so. It crashes the gui. This takes place in qt 4.8 on linux. A similar section of code is below which takes place on a QThread from my main gui.

Test.h
QBuffer *qbuff;
QByteArray qbyte;
Test.cpp

void Test::callExample()
{
    for (int i=0;i<10;i++)
    {
        wait(1);
        example();
    }
}

void Test::example()
{
    QFile inFile("/public/sounds/test.wav");  
    inFile.open(QIODevice::ReadOnly);
    QByteArray qbyte = inFile.readAll();
    inFile.close();
    qbuff=new QBuffer();
    qbuff->setData(qbyte);
    qbuff->open(QIODevice::ReadOnly); 
    qbuff->seek(0);
    audioOutput->start(qbuff);
}

In my full code, in example() I also have an event loop which, when finished, delete's qbuff and audioOutput. The error seems to come from various code locations, most often after an event change to idleState from event loop, but the actual problem should originate from the code shown. I have also tried moving the loop in callExample() to inside my eventloop, and even from my main thread (thus creating a new thread each call) but I still get the issue. I don't seem to get the error if there is no loop and the function is only called once or if the code takes place in my main gui rather than qthread.

JavaBeast
  • 766
  • 3
  • 11
  • 28
  • Post the actual code that exhibits the problem, not just an excerpt of it. If it's too big right now, then copy it and start reducing it down until either the problem vanishes (thus letting you do a binary search on the cause) or you have a small enough sample to post. An incomplete fragment is usually not worth people guessing about. – underscore_d Jan 08 '18 at 10:37
  • I only included my code so people could see the types of activities i was doing. A good answer need not be related to my code and can be more generic as to what the error actually means – JavaBeast Jan 08 '18 at 10:41

2 Answers2

1

Problem is a lifetime of your QByteArray qbyte;. It should be more or equal of lifetime of QBuffer *qbuff;. When you exit your example method, qbyte buffer is not exists anymore and your *qbuff became corrupted (points on non-existing object).

Possible, you want to write qbyte = inFile.readAll(); instead of declaring local variable?

void Test::example()
{
    QFile inFile("/public/sounds/test.wav");  
    inFile.open(QIODevice::ReadOnly);
    qbyte = inFile.readAll(); // Error was there, use your global variable
    inFile.close();
    qbuff=new QBuffer();
    qbuff->setData(qbyte);
    qbuff->open(QIODevice::ReadOnly); 
    qbuff->seek(0);
    audioOutput->start(qbuff);
}
Dmitry Sazonov
  • 8,801
  • 1
  • 35
  • 61
  • Thanks for the reply! I fixed what you mentioned but i think that issue would have caused a seg fault after this issue, either way nice catch :) Just to be sure I removed all deletes to see what would happen and still get I/O error. I have a feeling this issue has something to do with the QIODevice not ready or something? – JavaBeast Jan 08 '18 at 21:39
  • You should provide an SSCCE and/or use debugger. It's hard to be a telepath. – Dmitry Sazonov Jan 09 '18 at 10:26
0

I found this error to be produced when incorrectly handling memory management in or around QEventLoops, IODevices, and QThreads. As far as I can tell it can be troubleshoot just as you would a segment fault.

Two (very specific) scenarios that I found to cause this error:

-Creating a QEventLoop AND connecting to stateChange. If you need to use both, deleting items in the stateChange SLOT can create a race scenario updating values being used by the QEventLoop.

-If expect to manually emit finished() and have your QThread connected to it. If it is unknowingly triggered it can lead to processing variables that no longer exist if you didn't code accordingly.

JavaBeast
  • 766
  • 3
  • 11
  • 28