Results 1 to 6 of 6

Thread: How to convert QIcon to BASE64 or save it to file?

  1. #1
    Join Date
    Feb 2008
    Location
    Russia, Moscow
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question How to convert QIcon to BASE64 or save it to file?

    Hi 2 all.

    Please, help.
    How I can convert QIcon to BASE64?

    UPD

    I make it in thread. And QPixmap says that it is not save to use it outside GUI thread.
    "QPixmap: It is not safe to use pixmaps outside the GUI thread"

    How?

    this is a piece of my code:

    Qt Code:
    1. QDir dir( path );
    2. foreach (QFileInfo rootDir, dir.entryInfoList() )
    3. {
    4. QIcon ico = icon.icon( rootDir );
    5. }
    To copy to clipboard, switch view to plain text mode 

    I make a threaded media-server and I will paste Icons of files to web interface. How I can do this?


    UPD 2

    Or how I can save QIcon to file?
    Last edited by Alex Snet; 26th April 2009 at 19:20. Reason: update

  2. #2
    Join Date
    Apr 2009
    Location
    China
    Posts
    127
    Thanks
    30
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to convert QIcon to BASE64 or save it to file?

    This is what I find:
    Qt Code:
    1. QString filename = QFileDialog::getOpenFileName(this, tr("选择要添加的程序"), qApp->applicationDirPath(), tr("Excutable(*.*)"));
    2. if(filename.isEmpty())
    3. {
    4. return;
    5. }
    6.  
    7. QFileInfo fileInfo(filename);
    8. QIcon icon = seekIcon.icon(fileInfo);
    9. QPixmap pixmap = icon.pixmap(QSize(15, 15));
    10. if(!pixmap.save(tr("%1.png").arg(fileInfo.baseName()), "png"))
    11. {
    12. qDebug() << "Save icon failed!!";
    13. return;
    14. }
    15. else
    16. {
    17. qDebug() << "Save icon succeeded!!!";
    18. }
    To copy to clipboard, switch view to plain text mode 

    hope it can help you!

  3. #3
    Join Date
    Feb 2008
    Location
    Russia, Moscow
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to convert QIcon to BASE64 or save it to file?

    Thank U for try. But I can't use QPixmap in thread. It just doesn't work in thread.
    Any ideas?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to convert QIcon to BASE64 or save it to file?

    Convert the icon to QImage in the main thread and then pass it to the other thread. On the other hand then you don't need the other thread - you can just encode the image into base64 and save it to a file from the main thread.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Feb 2008
    Location
    Russia, Moscow
    Posts
    35
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to convert QIcon to BASE64 or save it to file?

    Ok. But how I can say to the main thread from socket thread to open Icon?
    I get file name in thread. It's just a small HTTP server. And I wanna set icons to files and folders.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to convert QIcon to BASE64 or save it to file?

    I don't know the structure of your program so it's hard to give a ready-made solution. Signals and slots seem to be a good candidate although the real question is if you need threads at all.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Storing/retrieving a QIcon from a database
    By KShots in forum Qt Programming
    Replies: 5
    Last Post: 1st June 2008, 02:55
  2. setIcon() - different QIcon states?
    By AaronMK in forum Qt Programming
    Replies: 1
    Last Post: 29th January 2008, 03:10
  3. Make error with Qt Jambi 4.3.2_01
    By pamalite in forum Installation and Deployment
    Replies: 0
    Last Post: 22nd November 2007, 12:05

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.