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. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Cascades Development

Reply
Developer
bskania
Posts: 105
Registered: ‎04-24-2012
My Carrier: relience

QUrl error to load Images dynamically in cascades

Hello,

 

I want to load the images from the photos folder in my app.

So I am fetching all the files from that directory and passing the image path to my ImageViewSource as QUrl.

but its giving me erroe as Invalid URL.

I am trying this from last 3 hours. but still not succeded.

 

My code

   

    qml->setContextProperty("app", this);
    QDir home = QDir::current();
    QString path(home.path());
    path.append(QDir::separator()).append("shared/photos");
    path = QDir::toNativeSeparators(path);
    qDebug() << "path" << home.rootPath() << home.currentPath()
            << home.homePath();
    home = QDir(path);
    qDebug() << home.absolutePath();
    if (home.exists()) {
        qDebug() << "exist";
        home.setFilter(QDir::Files);
        QStringList _listoffiles = home.entryList();
        qDebug() << "total files" << _listoffiles.size();
        _image_path = new QList<QString>();
        _image_path->append(_listoffiles);
        _currentIndex = 0;
    }

 

    AbstractPane *root = qml->createRootNode<AbstractPane>();
    _centerImage = root->findChild<ImageView*>("imageViewID");
    qDebug() << "image path" << _image_path->at(_currentIndex);
    path.append(QDir::separator()).append(_image_path->at(_currentIndex));
    path = QDir::toNativeSeparators(path);
    qDebug() << "url path " << path;
    if (QFile::exists(path)) {
        qDebug() << "file exist";
//        QUrl url = QUrl::fromLocalFile("asset:///images/Tulips.jpg");
        QUrl url = QUrl::fromLocalFile(path);
        qDebug() << url.errorString() << url.toLocalFile();

        if (_centerImage != NULL) {            
            _centerImage->setImageSource(url);


            qDebug() << "center image";
        }

    }
    Application::setScene(root);

 

Thanks in advance,

bskania

  

 

Please use plain text.
Developer
borceg
Posts: 659
Registered: ‎03-21-2012
My Carrier: Vip

Re: QUrl error to load Images dynamically in cascades

[ Edited ]

QDir home = QDir::current();
returns the root directory for your application (which is /accounts/1000/appdata/=DEPENDS OF APP ID HASH=/data).

Use this:

QDir home("/accounts/1000/shared/");
home.cd("/accounts/1000/shared/"); <-- OPTIONAL

Please use plain text.
Developer
bskania
Posts: 105
Registered: ‎04-24-2012
My Carrier: relience

Re: QUrl error to load Images dynamically in cascades

Hello

 

thanks for the suggestion.

But first I had used only this then I had tried with home directory.

 

But there is no difference in error.

 

regards

bskania

Please use plain text.
Developer
borceg
Posts: 659
Registered: ‎03-21-2012
My Carrier: Vip

Re: QUrl error to load Images dynamically in cascades

Which line fails now ?
Please use plain text.
Developer
bskania
Posts: 105
Registered: ‎04-24-2012
My Carrier: relience

Re: QUrl error to load Images dynamically in cascades

QUrl url = QUrl::fromLocalFile(path);
qDebug() << url.errorString() << url.toLocalFile();
Please use plain text.
Developer
soaman
Posts: 610
Registered: ‎03-03-2011
My Carrier: Mobitel

Re: QUrl error to load Images dynamically in cascades

I don't un derstand. Is the last line problematic?

I am usually using (example):
cout << " - " << reply->errorString().toUtf8().constData();
--------------------------------------------------------

Follow our developer blog on Slovenia BlackBerry Developer Group!
Please use plain text.
Developer
bskania
Posts: 105
Registered: ‎04-24-2012
My Carrier: relience

Re: QUrl error to load Images dynamically in cascades

I am still getting error message in url.errorString() as Invalid Url while I am passing the local file address,
I had posted my code in my first post.

bskania.

Please use plain text.
BlackBerry Development Advisor
amarcon
Posts: 155
Registered: ‎07-16-2012
My Carrier: Bell

Re: QUrl error to load Images dynamically in cascades

Hi bskania,

did you have any luck with this? Perhaps there is an issue with your path? Did you already check url before qDebug?

There is a Knowledge Base article about this, within some functions to get the dir, image path, etc...

Hope this helps.

 

http://supportforums.blackberry.com/t5/Cascades-Development-Knowledge/Using-QImage-and-QPainter-to-P...

 

Please use plain text.
Developer
bskania
Posts: 105
Registered: ‎04-24-2012
My Carrier: relience

Re: QUrl error to load Images dynamically in cascades

Hello..I don't know which is the problem exactly. But Today I ran same function again and its now working perfectly. Same code is working.

I had read already this document before creating the URL.

Thanks for your help.
Please use plain text.