Results 1 to 6 of 6

Thread: QFileIconProvider problem

  1. #1
    Join Date
    Dec 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QFileIconProvider problem

    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.

    Qt Code:
    1. https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2
    To copy to clipboard, switch view to plain text mode 

    Now consider the code below

    Qt Code:
    1. QString glink = QString("https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2");
    2.  
    3. QFileInfo finfo(glink);
    4.  
    5.  
    6. QIcon ico = ficon.icon(finfo);
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileIconProvider problem

    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.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  3. #3
    Join Date
    Dec 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileIconProvider problem

    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

    Qt Code:
    1. QString glink = QString("http://www.google.com");
    2.  
    3. QFileInfo finfo(glink);
    4.  
    5.  
    6. QIcon ico = ficon.icon(finfo);
    To copy to clipboard, switch view to plain text mode 

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

    Qt Code:
    1. https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2
    To copy to clipboard, switch view to plain text mode 

    and thats the problem.

  4. #4
    Join Date
    Jul 2009
    Location
    Enschede, Netherlands
    Posts
    462
    Thanked 69 Times in 67 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileIconProvider problem

    Qt 4.6.3:
    Qt Code:
    1. #include <QApplication>
    2. #include <QFileInfo>
    3. #include <QIcon>
    4. #include <QFileIconProvider>
    5. #include <QtDebug>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10.  
    11. QFileInfo gmail("https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2");
    12. QFileInfo google("http://www.google.com");
    13. qDebug() << gmail.absoluteFilePath();
    14. qDebug() << google.absoluteFilePath();
    15. QFileIconProvider iconProvider;
    16. QIcon gmailIcon = iconProvider.icon(gmail);
    17. QIcon googleIcon = iconProvider.icon(google);
    18. qDebug() << gmailIcon.isNull() << googleIcon.isNull();
    19. return 0;
    20. }
    To copy to clipboard, switch view to plain text mode 

    results in:
    Qt Code:
    1. "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%3Fui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2"
    2. "C:/devsw/qicontest-build-desktop/http:/www.google.com"
    3. true true
    To copy to clipboard, switch view to plain text mode 

    Summarizing: I get two null icons.
    Horse sense is the thing that keeps horses from betting on people. --W.C. Fields

    Ask Smart Questions

  5. The following user says thank you to franz for this useful post:

    rittchat (29th November 2010)

  6. #5
    Join Date
    Dec 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileIconProvider problem

    Thanks for the reply. I will try your cde and let you know.

  7. #6
    Join Date
    Dec 2009
    Posts
    26
    Thanks
    3
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileIconProvider problem

    Qt Code:
    1. "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%3Fui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2"
    2. "C:/Documents and Settings/user/My Documents/Qt Projects/iconTest-build-desktop/http:/www.google.com"
    3. false true
    To copy to clipboard, switch view to plain text mode 

    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?

    Qt Code:
    1. "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%3Fui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2"
    2. "C:/Qt/ic-build-desktop/http:/www.google.com"
    3. true true
    To copy to clipboard, switch view to plain text mode 

    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:


    Qt Code:
    1. #include <QApplication>
    2. #include <QFileInfo>
    3. #include <QIcon>
    4. #include <QFileIconProvider>
    5. #include <QtDebug>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication a(argc, argv);
    10.  
    11. QFileInfo gmail("https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fui%3Dhtml%26zy%3Dl&bsv=1eic6yu9oa4y3&scc=1&ltmpl=default&ltmplcache=2");
    12. QFileInfo google("http://www.google.com");
    13. qDebug() << gmail.absoluteFilePath();
    14. qDebug() << google.absoluteFilePath();
    15. gmail.setFile(gmail.absoluteFilePath()); // this is the trick ...
    16. QFileIconProvider iconProvider;
    17. QIcon gmailIcon = iconProvider.icon(gmail);
    18. QIcon googleIcon = iconProvider.icon(google);
    19. qDebug() << gmailIcon.isNull() << googleIcon.isNull();
    20. return 0;
    21. }
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by rittchat; 29th November 2010 at 05:02.

Similar Threads

  1. Getting mulitiple size file icons with QFileIconProvider
    By gmat4321 in forum Qt Programming
    Replies: 1
    Last Post: 19th March 2009, 14:41
  2. Replies: 4
    Last Post: 7th January 2009, 11:13
  3. Replies: 9
    Last Post: 29th March 2007, 14:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.