PDA

View Full Version : How to add qsvg



Aceman2000
26th January 2008, 18:00
Hi,

I have an app, which has some .svg files as resources. These get passed to QIcon constructors. When my app is built dynamically, everything works, but I want to build my app statically. When I do that, the icons disappear. Sometimes I get errors from QObject::moveToThread saying that some object not being in the corrent thread (I'm not calling moveToThread), and that my ':/something.svg' files cannot be loaded because Unknown error. I also can't add qsvg to my application, because I get wierd "undefined reference to `qt_plugin_instance_qsvg()'" errors.

Thanks for any help.

wysota
26th January 2008, 18:08
You need an SVG icon engine to be present in your application. If you compiled the application statically, you have to import the appropriate static plugin into your application. See the docs about static plugins for more details.

Aceman2000
26th January 2008, 19:25
Thanks for your reply,

I've read the doc like a thousand times (so if the solution really is there, I have selective vision ;) ). I did add a QT_PLUGIN += qsvg line to my .pro file, and also a Q_IMPORT_PLUGIN(qsvg) above my main(). This is producing the linker error (undefined reference to qt_plugin_instance_qsvg() ). It looks I'm missing something, but I can't figure out what... :o

wysota
26th January 2008, 20:04
Do you have the static plugin compiled?

Aceman2000
26th January 2008, 20:37
Afaik, yes. I have libqsvg4.a, libqsvg.a, libqsvgd.a, and qsvg4.dll in qt/4.3.3/plugins/iconengines

Aceman2000
29th January 2008, 11:19
up .

jacek
29th January 2008, 22:34
Do you use QMake binary from static Qt build? That linker error about plugin instance usually appears when you link a normal non-static plugin with your application.

Aceman2000
1st February 2008, 15:17
I have configured Qt with -static -release -no-exceptions.

jacek
1st February 2008, 20:39
Do you have more than one Qt version installed?

Aceman2000
1st February 2008, 20:41
No, only 4.3.3, and it's in the default directory, too.

jacek
1st February 2008, 22:14
Do you compile your application in the release mode?

Aceman2000
1st February 2008, 23:21
Yes. The linker error is in main.o (main.cpp contains the Q_IMPORT_PLUGIN(qsvg) line). Also, my project file now contains every combination of QT, _, PLUGIN, PLUGINS, +=, and qsvg that seems logical :)

wysota
2nd February 2008, 00:00
Could you show us the sizes of files in iconengines? ls -l will do the trick on U*ix systems.

jacek
2nd February 2008, 13:01
Could you post the command that make uses to link your application?

Run make > somefile.txt and find the line with -lqsvg in somefile.txt.

Aceman2000
2nd February 2008, 13:51
Make stdout:

mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory `D:/prog/qt/sendfile'
g++ -static -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -Wl,-subsystem,windows -o release\sendfile.exe object_script.sendfile.Release -L"c:\Qt\4.3.3\lib" -lmingw32 -lqtmain -LC:/Qt/4.3.3/plugins/iconengines -lqsvg4 -lQtXml -lQtGui -lQtNetwork -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore -lkernel32 -luser32 -lshell32 -luuid -lole32 -ladvapi32 -lws2_32
mingw32-make[1]: Leaving directory `D:/prog/qt/sendfile'

-lqsvg doesn't appear, not even with

LIBS += -L$$[QT_INSTALL_PLUGINS]/iconengines -lqsvg

Dir in iconengines:

29 508 libqsvg.a
2 146 libqsvg4.a
1 255 072 libqsvgd.a
45 568 qsvg4.dll

wysota
2nd February 2008, 14:06
You have two installations mixed up. libqsvg4.a and qsvg4.dll are an import and dynamic libraries from a shared installation and libqsvg.a and libqsvgd.a are static plugins (release and debug version respectively). I suggest moving libqsvg4.a and the dll out of the directory as the first thing to do as your application tries to link against the dynamic version of the plugin instead of the static one - hence the error.

And by the way, what is the contents of your lib subdirectory of the Qt installation? Do those libraries have .a or .dll extensions? If .a files have small sizes, they are import modules for dynamic libraries and not static versions of them.

Aceman2000
2nd February 2008, 14:10
I used the Qt installer, and then ran a configure command. Will reinstall, maybe it cleans things up...

wysota
2nd February 2008, 14:30
Why did you run configure? If you ran configure, then you should run make afterwards. Do you want a static compilation or is it just a way to solve your svg problems?

Aceman2000
2nd February 2008, 19:30
I'm following these instructions: http://wiki.qtcentre.org/index.php?title=Building_static_Qt_on_Windows

I was misunderstandable, I did run configure AND make. Sorry about that. I want one exe file that needs no DLL's.

wysota
2nd February 2008, 22:20
So I suggest you download the source code only and then configure and make. Don't install binaries or you'll be mixing two installations.

Aceman2000
3rd February 2008, 11:44
Problem solved!

I'm not sure what solved it, so here's a list of what I did:

-uninstall Qt, remove any remaining files by hand
-reinstall Qt
-edit the g++ mkspecs (add -static to lflags)
-configure -static -release -no-qt3support -no-exceptions -no-qmake -fast
-make sub-corelib,sub-gui,sub-network,sub-svg, and sub-plugins (maybe I forgot one)

My .pro file's relevant lines are now

QT += svg
QTPLUGIN += qsvg
LIBS += -L$$[QT_INSTALL_PLUGINS]/iconengines
LIBS += $$[QT_INSTALL_PLUGINS]/iconengines/libqsvg.a

With this, my program compiles and shows the icons when run.

Thanks!

wysota
3rd February 2008, 11:51
-edit the g++ mkspecs (add -static to lflags)
Huh? What for? Running configure -static should have taken care of that.

Aceman2000
3rd February 2008, 11:54
Because this (http://wiki.qtcentre.org/index.php?title=Building_static_Qt_on_Windows) says so :)

jpn
3rd February 2008, 12:02
Huh? What for? Running configure -static should have taken care of that.
As far as I remember it was required to kill dependency to mingwm10.dll. Notice that -static is added to QMAKE_LFLAGS. All what "configure -static" does is that it adds "CONFIG += static" which is not enough to kill the aforementioned dependency.

wysota
3rd February 2008, 12:07
It's just for convenience, so that you don't have to add it to your projects. But ok, if J-P says it's "required" then let's agree it is :)

jpn
3rd February 2008, 12:11
It's just for convenience, so that you don't have to add it to your projects. But ok, if J-P says it's "required" then let's agree it is :)
Heh, but you would have to add it to Qt project as well, wouldn't you?

wysota
3rd February 2008, 12:15
Only if you didn't want MinGW dependencies. And let's face it, most Windows machines do have that library installed.

jpn
3rd February 2008, 12:20
Only if you didn't want MinGW dependencies. And let's face it, most Windows machines do have that library installed.
I'm afraid I have to disagree with that. Usually you have mingwm10.dll available if and only if you have MinGW installed AND its bin folder added to PATH.

Aceman2000
3rd February 2008, 18:08
I agree, at first (long time ago) my program didn't even execute (complaining about mingwm10.dll), only when I ran it from a Qt command prompt (which 'fixed' PATH).