问题
I have a *.ico file.
The icon is loaded by the setWindowIcon() function. I added a *.ico file to the resource file. When I launch the application from Qt Creator, the icon is displayed correctly. But when I launch the application from outside Qt Creator, the icon is not displayed. The application successfully starts and works, but the icon is not displayed.
this->setWindowIcon(QIcon(":/icon/MiniAMR.ico")); // OK, icon load (inside Qt)
/* this string in .pro-file */
RESOURCES += \
res.qrc
Please, help.
回答1:
You most likely need to copy the plugins/imageformats/qico.dll
file from the Qt installation you're building with to within your executable's directory. Put it in a subfolder, like so: <your_executable>/imageformats/qico.dll
. If testing a debug build, you'll need the d
suffix version of the dll (qicod.dll
).
When run from QtCreator, it sets up the correct environment variables so that your application knows where to find the Qt plugins. When run outside of QtCreator, your app probably can't find the plugin.
来源:https://stackoverflow.com/questions/55515996/the-icon-does-not-load-when-you-start-the-application-from-the-outside-qt-creato