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
Posts: 105
Registered: ‎04-24-2012
My Device: blackberry developer
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

  

 

Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
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

Developer
Posts: 105
Registered: ‎04-24-2012
My Device: blackberry developer
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

Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB
My Carrier: Vip

Re: QUrl error to load Images dynamically in cascades

Which line fails now ?
Developer
Posts: 105
Registered: ‎04-24-2012
My Device: blackberry developer
My Carrier: relience

Re: QUrl error to load Images dynamically in cascades

QUrl url = QUrl::fromLocalFile(path);
qDebug() << url.errorString() << url.toLocalFile();
Developer
Posts: 849
Registered: ‎03-03-2011
My Device: Z10

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();
--------------------------------------------------------------------------------------
Leader of Ljubljana BlackBerry Developer Group
BlackBerry Certified Builder for Native Application Development
Developer
Posts: 105
Registered: ‎04-24-2012
My Device: blackberry developer
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.

BlackBerry Development Advisor (Retired)
Posts: 155
Registered: ‎07-16-2012
My Device: Dev Alpha
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...

 

Developer
Posts: 105
Registered: ‎04-24-2012
My Device: blackberry developer
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.