I am using SVG icons in my application from the ressource file, but when I run the app the icons are just not displayed. Using jpg icons in the same way works pretty fine.
SVG images can be written directly into the HTML document using the <svg> </svg> tag. To do this, open the SVG image in VS code or your preferred IDE, copy the code, and paste it inside the <body> element in your HTML document. If you did everything correctly, your webpage should look exactly like the demo below.
Qt supports the static features of SVG 1.2 Tiny. ECMA scripts and DOM manipulation are currently not supported. SVG drawings can be rendered onto any QPaintDevice subclass.
Scalable Vector Graphics, or SVGs, are a generally a good choice for use as icons on your website, because they are vector graphics. Vector graphics can be scaled to any size without losing quality.
Since Qt5.1 the framework has been modularized. Most likely you are missing the svg module. The application will still compile without complaining.
Make sure the SVG module is installed on your system and linked (with qmake (Howto), cmake (Howto) or plain make). If it was linked successfully QImageReader::supportedImageFormats() will list SVG.
If you're using cmake, you need something like this to link Svg Qt libraries.
find_package(Qt5Svg REQUIRED)
target_link_libraries( ${APP_NAME} Qt5::Svg )
A full example (sorry ManuelSchneid3r) could be the following one.
## application name
set( APP_NAME "myapp" )
## project name
project( ${APP_NAME} )
## require a minimum version of CMake
CMAKE_MINIMUM_REQUIRED ( VERSION 2.6 FATAL_ERROR )
## add definitions, compiler switches, etc.
ADD_DEFINITIONS( -Wall -O2 )
SET( CMAKE_CXX_FLAGS -g )
## include (or not) the full compiler output
SET( CMAKE_VERBOSE_MAKEFILE OFF )
# find Qt
find_package(Qt5Widgets REQUIRED)
find_package(Qt5Core REQUIRED)
find_package(Qt5Gui REQUIRED)
find_package(Qt5Svg REQUIRED)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
include_directories(${Qt5Core_INCLUDE_DIRS})
include_directories(${Qt5Gui_INCLUDE_DIRS})
include_directories(${Qt5Svg_INCLUDE_DIRS})
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
# The AUTOUIC target property controls whether cmake(1) inspects the
# C++ files in the target to determine if they require uic to be run,
# and to create rules to execute uic at the appropriate time.
set(CMAKE_AUTOUIC ON)
## sources
file( GLOB MAIN_SRC *.cpp )
set( SOURCES ${MAIN_SRC} )
## executable
add_executable( ${APP_NAME} ${SOURCES} )
## link
target_link_libraries( ${APP_NAME} Qt5::Widgets Qt5::Svg )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With