c++qt

Qt can i set resources programmatically?


in Qt c++ , is there any way to set resources programmatically?
i want to let the user to set the exe icon and his html file that will be loaded into the application(QtWebKit).
so it will embedded in to the application that is currently are compiled using the resource Collection Files (.qrc)


Solution

  • Windows doesn't "let" the user set the "exe" icon -- not without extra tools or code. You're free of course to use Windows APIs to modify the executable, but this is not guaranteed to work. If the application is installed in a safe manner, it'll run without administrative privileges and won't be able to modify its icon. Basically: it's a bad idea. Don't do it.

    You can of course change the icon of the application at runtime by using the following code:

    void setIcon(QWidget* widget, QPixmap* pixmap);
    {
       WId wid = widget->winId();
       HINSTANCE inst = (HINSTANCE)qWinAppInst();
       QPixmap large = pixmap->scaled(48, 48, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
       SendMessage(wid, WM_SETICON, ICON_BIG, (LPARAM)large->toWinHICON());
       QPixmap small = pixmap->scaled(24, 24, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation);
       SendMessage(wid, WM_SETICON, ICON_SMALL, (LPARAM)small->toWinHICON());
    }