Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <functional>
- #include <QDebug>
- #include <QtConcurrent/QtConcurrentMap>
- #include <QtConcurrent/QtConcurrentRun>
- #include <QDir>
- #include <QImage>
- #include <QMutexLocker>
- #include <QStringList>
- #include "loadImages.hpp"
- loadImages::loadImages(QObject *parent) : QObject(parent)
- {
- namespace ph = std::placeholders;
- QStringList names;
- names<<"/Users/yyyy/Downloads/1359170070532.jpg"<<"/Users/yyyy/Downloads/1370902954521.jpg"
- <<"/Users/yyyy/Downloads/1370968889277.jpg"<<"/Users/yyyy/Downloads/1373155482891.jpg";
- for(auto const &data: names){
- QImage img(data);
- qDebug()<<names<<" is null : "<<img.isNull();
- }
- QThreadPool::globalInstance()->setMaxThreadCount(1);
- QtConcurrent::map(names, std::bind(&loadImages::loadImagesImpl, this, ph::_1)); //always crash
- //QtConcurrent::run(this, &loadImages::loadImagesImpl_2, names); //work fine
- }
- void loadImages::loadImagesImpl_2(QStringList const &names)
- {
- for(auto const &data: names){
- QImage img(data);
- }
- }
- void loadImages::loadImagesImpl(QString const &name)
- {
- //I don't think we need a mutex at here, but I want to give this "workaround" a try
- //no matter I add this mutex or not, the program always crash
- QMutexLocker lock(&mutex_);
- QImage img(name);
- }
Advertisement
Add Comment
Please, Sign In to add comment