Skip to content

Instantly share code, notes, and snippets.

@kanryu
Created August 4, 2017 13:36
Show Gist options
  • Select an option

  • Save kanryu/61ba6e9828e1553095cc85375a8cc85d to your computer and use it in GitHub Desktop.

Select an option

Save kanryu/61ba6e9828e1553095cc85375a8cc85d to your computer and use it in GitHub Desktop.
malloc() fails in QtConcurrent::run()
QImage createImageAsync(QString path)
{
QImageReader reader(path);
if(!reader.canRead())
return QImage();
// QImage processing sometimes fails
QImage src;
int count = 0;
do {
//src = QImage::fromData(bytes, QFileInfo(path.toLower()).suffix().toUtf8());
src = reader.read();
if(!src.isNull())
break;
if(src.isNull() && count++ < 1000) {
QThread::currentThread()->usleep(1000);
continue;
}
return QImage();
} while(1);
return src;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment