0

I'm trying to save a QIcon in a settings.ini using QSettings.

I'm saving the icon this way:

   QIcon icon = button->icon();
   if (!icon.isNull())
      iniSettings->setValue("icon", icon.pixmap(32, 32).toImage());

And trying to load it as:

   qDebug() << iniSettings->value("icon");
   QIcon icon = iniSettings->value("icon").value<QIcon>();
   if (!icon.isNull())
      button->setIcon(icon);

But icon is NULL, whats wrong?

Pamputt
  • 173
  • 1
  • 11
Cesar
  • 41
  • 2
  • 5
  • 16
  • 1
    Save `QPixmap` instead `QImage`, then reading QIcon may work because Qt has `QIcon(const QPixmap&)` constructor. If you stay with saving QImage, to create QIcon you should do the following: read QImage from QSettings, then create QPixmap by `QPixmap::fromImage` and create QIcon by `QIcon(const QPixmap&)`. – rafix07 May 25 '23 at 11:46

0 Answers0