07-31-2012 08:47 AM
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/pho
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
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
07-31-2012 10:27 AM - edited 07-31-2012 10:28 AM
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
08-01-2012 12:45 AM
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
08-01-2012 04:20 AM
08-01-2012 08:19 AM
08-01-2012 05:27 PM
08-03-2012 02:07 AM
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.
08-09-2012 04:44 PM
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.
08-16-2012 03:24 AM