PDA

View Full Version : QFileIconProvider problem



rittchat
26th November 2010, 05:49
Hi,

I am using windows XP SP3, Qt 4.7.1

I am facing a strange problem.

The following line is the web address of gmail.


https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3F ui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2

Now consider the code below



QString glink = QString("https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3F ui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2");

QFileInfo finfo(glink);

QFileIconProvider ficon;

QIcon ico = ficon.icon(finfo);


Now strangely the ico contains the icon of MyComputer. Because glink contains the path of no file or folder or symlink QFileIconProvider should return a null icon.

Is it a bug? How should I write some code such that whenever QFileIconProvider gets a webpage link it return a null icon?

thanks

franz
26th November 2010, 20:37
I have a slight suspicion that, since QFileIconProvider only works with QFileInfo and QFileInfo afaik only does local files, the url you put in, resolves to / (root) and therefore give you a 'system' icon.

rittchat
27th November 2010, 06:23
Thanks franz for the reply. You may be right but QFileIconProvider is providing system icon ONLY if the corresponding QFileInfo have that particular path. For example consider the following code



QString glink = QString("http://www.google.com");

QFileInfo finfo(glink);

QFileIconProvider ficon;

QIcon ico = ficon.icon(finfo);


Now ico has null icon (as expected). QFileIconProvider is returning a system icon only if the path is



https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3F ui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2


and thats the problem.

franz
27th November 2010, 10:46
Qt 4.6.3:


#include <QApplication>
#include <QFileInfo>
#include <QIcon>
#include <QFileIconProvider>
#include <QtDebug>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QFileInfo gmail("https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3F ui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2");
QFileInfo google("http://www.google.com");
qDebug() << gmail.absoluteFilePath();
qDebug() << google.absoluteFilePath();
QFileIconProvider iconProvider;
QIcon gmailIcon = iconProvider.icon(gmail);
QIcon googleIcon = iconProvider.icon(google);
qDebug() << gmailIcon.isNull() << googleIcon.isNull();
return 0;
}


results in:


"C:/devsw/qicontest-build-desktop/https:/www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3F ui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2"
"C:/devsw/qicontest-build-desktop/http:/www.google.com"
true true


Summarizing: I get two null icons.

rittchat
28th November 2010, 11:54
Thanks for the reply. I will try your cde and let you know.

rittchat
29th November 2010, 04:02
"C:/Documents and Settings/user/My Documents/Qt Projects/iconTest-build-desktop/https:/www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3F ui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2"
"C:/Documents and Settings/user/My Documents/Qt Projects/iconTest-build-desktop/http:/www.google.com"
false true


The above is the result that I get when I run your code. My Qt is 4.7.1. So is it a Qt specific problem?



"C:/Qt/ic-build-desktop/https:/www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3F ui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2"
"C:/Qt/ic-build-desktop/http:/www.google.com"
true true


I run another test of your code and get two null icon.

I think I got the reason why I got one non-null icon as in my previous post. I think the reason is the following

previously my build directory was "C:/Documents and Settings/user/My Documents/Qt Projects/iconTest-build-desktop/" which has lots of spaces in the path.

Now it is "C:/Qt/ic-build-desktop/" which don't has any space.
I think this spaces are creating the problem.

Added after 8 minutes:



#include <QApplication>
#include <QFileInfo>
#include <QIcon>
#include <QFileIconProvider>
#include <QtDebug>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QFileInfo gmail("https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3F ui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2");
QFileInfo google("http://www.google.com");
qDebug() << gmail.absoluteFilePath();
qDebug() << google.absoluteFilePath();
gmail.setFile(gmail.absoluteFilePath()); // this is the trick ...
QFileIconProvider iconProvider;
QIcon gmailIcon = iconProvider.icon(gmail);
QIcon googleIcon = iconProvider.icon(google);
qDebug() << gmailIcon.isNull() << googleIcon.isNull();
return 0;
}


I have solved the problem by passing the absoluteFilePath() to the QFileInfo. Now it is returning two null icons as expected. Thanks you very much franz for your help. :)