QT 5.4, Unable to access Resource from code

前端 未结 2 1523
清酒与你
清酒与你 2021-01-28 07:58

I try to include style images of my app into a q-resource file. When I include the file directly in the code, it work, but when i try to use QResource, it fail (do not load the

2条回答
  •  有刺的猬
    2021-01-28 08:28

    QResource::registerResource("darkstyle.qrc") registers the resource description. If you want to use resources dynamically like this you need to register the compiled resources themselves. Run rcc -binary darkstyle.qrc -o darkstyle.rcc and use QResource::registerResource("darkstyle.rcc")

    Alternatively, compile the resources into your binary directly. Do do so, use RESOURCES += darkstyle.qrc in your .qrc, and leave out the QResource::registerResource.

提交回复
热议问题