QtSvg on Linux doesn't work
-
Hi, I'm developing an application on Windows and Linux, but when I try to build it on Linux, I have a problem. I'm using svg files, which work fine on Windows, but when I try to run it on Linux, it doesn't work. I checked the files and all seems to be good. I don't know why it doesn't work.
-
@Sucharek said in QtSvg on Linux doesn't work:
I checked the files and all seems to be good. I don't know why it doesn't work.
Very hard to help you with this description!
Work's for me (™)One tip: did you check filename case... Linux file system is case-sensitive
-
Hi, so I fixed it. I initialized the svg file paths when declaring the variable, and that works on Windows, but for some reason not on Linux. I had:
QGraphicsSvgItem *svg = new QGraphicsSvgItem("path/to/svg.svg");
on the top, but that doesn't work. I only had to add:
QGraphicsSvgItem *svg;
at the top, and declare it in the void that has "ui->setupUi(this);" in it (don't know what's the name of that part):
ui->setupUi(this); svg = new QGraphicsSvgItem("path/to/svg.svg");
-
@Sucharek said in QtSvg on Linux doesn't work:
on the top
Assuming that means "at the top of a source file, outside of any method" you should never create a
new QGraphicsSvgItem
there (nor more or less any Qt UI object). Your statement will execute before you have created theQApplication
in yourmain()
, and until then it is undefined behaviour to create any such UI object. You are "lucky" it worked in Windows at all.Also, for the record, does your
"path/to/svg.svg"
imply this is a relative path? Paths to such files should always be absolute (or in Qt resources). -
@Sucharek as @JonB pointed out, the placement "at the top fo source file" is not a good idea.
Given that you have these statements:
ui->setupUi(this);
svg = new QGraphicsSvgItem("path/to/svg.svg");which implies some kind of constructor for a widget, you may want to add
svg
as a member of that widget class (in the class header file):... private: ... QGraphicsSvgItem *svg; ...
then in the constructor you could do:
ui->setupUi(this); svg = new QGraphicsSvgItem("path/to/svg.svg", this);
to take advantage of Qt's memory management feature
(in your example, you must delete the svg object yourself...)