Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
nguafack
Posts: 44
Registered: ‎05-22-2013
My Device: Blackberry 10

QtConcurrent Using Member Functions doubts

[ Edited ]

Hi all,

 

I am writng some services to process QImages from bytes array. I will like to submit a list of bytes array to my map function and get a list of QImages in return.

 

Below is how I have tried to archieve this.

 

ImageProcessor

 

#include "ImageProcessor.hpp"

ImageProcessor::ImageProcessor(const QByteArray &imageData, QObject *parent)
	: QObject(parent)
	, m_data(imageData)
{

}

QImage ImageProcessor::start()
{
    QImage image;

    image.loadFromData(m_data);

    image = image.scaled(100, 100, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);

    // Image processing goes here, example could be adding water mark to the downloaded image

    return image;
}

 

Concurrent Map

 

void Image::processImages()
{
    QFuture<QImage> images = QtConcurrent::mapped(m_imageBytesList.begin(), m_imageBytesList.end(), &ImageProcessor::start);
}

 

 

 

Developer
saprykin
Posts: 271
Registered: ‎05-29-2013
My Device: BlackBerry Z10

Re: QtConcurrent Using Member Functions doubts

And the problem is?
-------------------------------------------------------------------------------
NSR Reader for BlackBerry 10 @NSRReader on Twitter
Me @xelfium on Twitter
Developer
nguafack
Posts: 44
Registered: ‎05-22-2013
My Device: Blackberry 10

Re: QtConcurrent Using Member Functions doubts

It does not compile, because the return type and the type in the list must be the same. 

 

Advice on a work around will be appreciated.

Developer
saprykin
Posts: 271
Registered: ‎05-29-2013
My Device: BlackBerry Z10

Re: QtConcurrent Using Member Functions doubts

Could you provide compiler error output?
-------------------------------------------------------------------------------
NSR Reader for BlackBerry 10 @NSRReader on Twitter
Me @xelfium on Twitter
Developer
nguafack
Posts: 44
Registered: ‎05-22-2013
My Device: Blackberry 10

Re: QtConcurrent Using Member Functions doubts

[ Edited ]

Thuogh I had change the code to use concurrent run, this is the error I was having 

 

error: conversion from 'QFuture<void>' to non-scalar type 'QFuture<QByteArray>' requested

 

Now I get a stackoverflow error on debugging, 

Cannot access memory at address 0x0   and control is direct to qtConcurrentrunbase

 

 

Developer
saprykin
Posts: 271
Registered: ‎05-29-2013
My Device: BlackBerry Z10

Re: QtConcurrent Using Member Functions doubts

The error is occured because mapped() method is a template one and returns QFuture<T>, where is T of the same type as the list you are iterating through. You are iterating thorugh m_imageBytesList which is of type QList<QByteArray>, thats why the compiler expects that mapped() method will return QFuture<QByteArray>.
-------------------------------------------------------------------------------
NSR Reader for BlackBerry 10 @NSRReader on Twitter
Me @xelfium on Twitter
Regular Contributor
lunaplena
Posts: 205
Registered: ‎06-11-2013
My Device: Blackbery z10

Re: QtConcurrent Using Member Functions doubts

Try specify the template path.

Developer
saprykin
Posts: 271
Registered: ‎05-29-2013
My Device: BlackBerry Z10

Re: QtConcurrent Using Member Functions doubts

It will not help. The problem is here:
QFuture<QImage> images
where is complier expects QFuture<QByteArray>
-------------------------------------------------------------------------------
NSR Reader for BlackBerry 10 @NSRReader on Twitter
Me @xelfium on Twitter
Developer
nguafack
Posts: 44
Registered: ‎05-22-2013
My Device: Blackberry 10

Re: QtConcurrent Using Member Functions doubts

I think the best way is to subclass QThread, which is what am doing now because I have two processor intensive processes.

 

1 loading bytes 

2 convert the image bytes to QImage and scale then bb::ImageData.

Regular Contributor
lunaplena
Posts: 205
Registered: ‎06-11-2013
My Device: Blackbery z10

Re: QtConcurrent Using Member Functions doubts

you have specified 

QByteArray in the constructor.