PDA

View Full Version : How to convert QIcon to BASE64 or save it to file?



Alex Snet
26th April 2009, 16:54
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:



QDir dir( path );
QFileIconProvider icon;
foreach (QFileInfo rootDir, dir.entryInfoList() )
{
QIcon ico = icon.icon( rootDir );
}


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?

sophister
27th April 2009, 16:10
This is what I find:

QString filename = QFileDialog::getOpenFileName(this, tr("选择要添加的程序"), qApp->applicationDirPath(), tr("Excutable(*.*)"));
if(filename.isEmpty())
{
return;
}

QFileInfo fileInfo(filename);
QFileIconProvider seekIcon;
QIcon icon = seekIcon.icon(fileInfo);
QPixmap pixmap = icon.pixmap(QSize(15, 15));
if(!pixmap.save(tr("%1.png").arg(fileInfo.baseName()), "png"))
{
qDebug() << "Save icon failed!!";
return;
}
else
{
qDebug() << "Save icon succeeded!!!";
}

hope it can help you!

Alex Snet
27th April 2009, 17:05
Thank U for try. But I can't use QPixmap in thread. It just doesn't work in thread.
Any ideas?

wysota
28th April 2009, 08:24
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.

Alex Snet
29th April 2009, 20:05
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.

wysota
29th April 2009, 22:39
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.