Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用QT并发映射时序列参数出错_Qt_Concurrency_Qimage_Qtconcurrent - Fatal编程技术网

使用QT并发映射时序列参数出错

使用QT并发映射时序列参数出错,qt,concurrency,qimage,qtconcurrent,Qt,Concurrency,Qimage,Qtconcurrent,我正在尝试使用QtConcurrent::map运行此函数 //This function is used through QtConcurrent::map to create images from a QString path void MainWindow::createQImage(QString* path) { //create an image from the given path QImage* t = new QImage(*path); image

我正在尝试使用QtConcurrent::map运行此函数

//This function is used through QtConcurrent::map to create images from a QString path
void MainWindow::createQImage(QString* path) {
    //create an image from the given path
    QImage* t = new QImage(*path);
    imageList->append(t);
}
在此容器/序列上(在mainwindow标头中声明,并在mainwindow构造函数中初始化)

QList*imageList=新的QList;
这是我试图运行的代码

QFutureWatcher<void> futureWatcher;
futureWatcher.setFuture(QtConcurrent::map(imageList, &MainWindow::createQImage));
QFutureWatcher未来观察者;
setFuture(QtConcurrent::map(imageList,&MainWindow::createQImage));
下面是我得到的错误:

request for member 'begin' in 'sequence', which is of non-class type 'QList<QImage*>*'
request for member 'end' in 'sequence', which is of non-class type 'QList<QImage*>*'
请求“sequence”中的成员“begin”,该成员属于非类类型“QList*”
请求“sequence”中的成员“end”,该成员属于非类类型“QList*”
我需要为“imageList”中的每个元素运行“createQImage”函数,它可以达到数千个。我认为问题在于map函数的第一个参数。从我所读到的,它可能与兼容性有关。网上没有太多我能联系到的示例代码。我是Qt新手,并不是最有经验的程序员,但我希望得到一些帮助和反馈

或者,是否有更好的方法使用QtConcurrent来实现这一点


提前谢谢

QtConcurrent::map
需要一个序列作为其第一个参数。您向它传递了一个指向序列的指针

如果你这样做

futureWatcher.setFuture(QtConcurrent::map(*imageList, &MainWindow::createQImage));
它应该是快乐的


请注意,编译器相当清楚问题所在。花点时间仔细阅读错误,它们通常不像一开始看起来那么神秘。在本例中,它告诉您传递的参数不是类类型。快速查看错误末尾的参数类型会发现它是一个指针。

QtConcurrent::map
需要一个序列作为其第一个参数。您向它传递了一个指向序列的指针

如果你这样做

futureWatcher.setFuture(QtConcurrent::map(*imageList, &MainWindow::createQImage));
它应该是快乐的


请注意,编译器相当清楚问题所在。花点时间仔细阅读错误,它们通常不像一开始看起来那么神秘。在本例中,它告诉您传递的参数不是类类型。快速查看错误末尾的参数类型会发现它是一个指针。

QList
QImage
QString
都是写时复制类型(请参阅),因此不应该使用指向这些类型的指针,因为它们基本上已经是智能指针


如果您从代码中删除了所有指针,也应该可以解决主要问题。

QList
QImage
QString
都是写时复制类型(请参阅),因此您不应该使用指向这些类型的指针,因为它们基本上已经是智能指针了


如果您从代码中删除了所有指针,它还应该解决主要问题。

另一方面,如果实现正确(请参阅其他答案),这将不会起任何作用
QtConcurrent::map()
迭代给定列表中的每个元素。由于您只在map函数中创建和附加元素,因此您的imageList最初将为空,因此您的
createQImage()
将永远不会被调用。相反,您可以使用非空、空填充的
QVector图像列表(numberOfImagesYouNeed,Q_NULLPTR)
并将其传递给map()。另一方面,如果实现正确(请参阅其他答案),这将不会起任何作用
QtConcurrent::map()
迭代给定列表中的每个元素。由于您只在map函数中创建和附加元素,因此您的imageList最初将为空,因此您的
createQImage()
将永远不会被调用。相反,您可以使用非空、空填充的
QVector图像列表(numberOfImagesYouNeed,Q_NULLPTR)
并将其传递给map()。