Guest User

Untitled

a guest
Jul 9th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.51 KB | None | 0 0
  1.     #include <functional>
  2.      
  3.     #include <QDebug>
  4.      
  5.     #include <QtConcurrent/QtConcurrentMap>
  6.     #include <QtConcurrent/QtConcurrentRun>
  7.     #include <QDir>
  8.     #include <QImage>
  9.     #include <QMutexLocker>
  10.     #include <QStringList>
  11.      
  12.     #include "loadImages.hpp"
  13.      
  14.     loadImages::loadImages(QObject *parent) : QObject(parent)
  15.     {
  16.         namespace ph = std::placeholders;
  17.         QStringList names;
  18.         names<<"/Users/yyyy/Downloads/1359170070532.jpg"<<"/Users/yyyy/Downloads/1370902954521.jpg"
  19.              <<"/Users/yyyy/Downloads/1370968889277.jpg"<<"/Users/yyyy/Downloads/1373155482891.jpg";
  20.      
  21.         for(auto const &data: names){
  22.             QImage img(data);
  23.             qDebug()<<names<<" is null : "<<img.isNull();
  24.         }
  25.      
  26.         QThreadPool::globalInstance()->setMaxThreadCount(1);
  27.      
  28.         QtConcurrent::map(names, std::bind(&loadImages::loadImagesImpl, this, ph::_1)); //always crash
  29.         //QtConcurrent::run(this, &loadImages::loadImagesImpl_2, names); //work fine
  30.     }
  31.      
  32.     void loadImages::loadImagesImpl_2(QStringList const &names)
  33.     {
  34.         for(auto const &data: names){
  35.             QImage img(data);
  36.         }
  37.     }
  38.      
  39.     void loadImages::loadImagesImpl(QString const &name)
  40.     {
  41.         //I don't think we need a mutex at here, but I want to give this "workaround" a try
  42.        //no matter I add this mutex or not, the program always crash
  43.         QMutexLocker lock(&mutex_);
  44.      
  45.         QImage img(name);
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment