2

I would like to use SVGs in menus and buttons around a Qt-4.7 application. The images are rendered correctly across linux and windows platforms, however an obnoxious message reading...

couldn't create image from ""

...is printed to the console seemingly as soon as one of these images is loaded or changes state (like highlighting or disabling its container widget). Over the course of the run of the application, many of these lines are printed, leaving a lot of senseless output crufted around reasonable application output.

Poking around the Qt code a bit, this appears to be coming from svg/qsvghandler.cpp:2680 where the line contains the following.

qDebug()<<"couldn't create image from "<<filename;

From the documentation for qDebug, you would think that I could block this by defining QT_NO_DEBUG_OUTPUT at compiletime, but this will only block the application's compiled debug calls, not the one in Qt's SVG library.

So I guess my question is actually two-fold:

  1. As in the title, why is Qt printing this even when rendering SVGs correctly?
  2. Without recompiling Qt or its SVG library, how do I prevent Qt from printing this and crufting the application's output?

I've also posted this question on the QtCentre forums.

perden
  • 647
  • 5
  • 20

3 Answers3

3

To #2: You can prevent qDebug output by using qIntallMsgHandler and writing a handler that just discard the message. Also see this question: How to redirect qDebug, qWarning, qCritical etc output?

Community
  • 1
  • 1
hmuelner
  • 8,093
  • 1
  • 28
  • 39
  • This definitely looks like the only option to suppress qDebug() output from the Qt libraries themselves from your own executables. Cool. – Arnold Spence May 06 '11 at 22:55
2

Re #1: I'm no expert on SVG but from the Qt source code where that line appears, it looks like Qt is trying to load an image file referenced in an xlink:href attribute. The output you see would seem to indicate that either the value for that attribute is "" or the value is a bunch of white space characters enclosed in "" which is removed by a call to QString.trimmed() which is then used as the name of an image file to be loaded into a QImage. I can't quite discern if the filename is ending up as an empty string or two quotes :)

I would have to guess that either the SVG files you have are filled with empty string xlink:href attributes (probably links or filenames for texture images) or there is something about the SVG file causing Qt to incorrectly parse it. I would lean towards the former.

What is your criteria for concluding that they are being rendered correctly? Perhaps you could open the SVG files in a text editor and look at the xlink:href occurances in it?

Arnold Spence
  • 21,942
  • 7
  • 74
  • 67
1

I've had a similar issue, I used Adobe Illustrator to create images and then save as SVG. The problem is that hidden layers in Illustrator still gets written to the SVG file, but its display property is set to "none". In my case a hidden layer of a file I "placed" - to get an idea if the background I'm creating would look OK.

This causes your image to render correctly as you say, but Qt complains about the missing invisible layer in the SVG file. If you open the SVG file in a text viewer you might find the hidden layer looks something like this:

 <g id="bglogo_x5F_splash" style="display:none;">
    <image style="display:inline;overflow:visible;" width="1740" height="438" xlink:href="../logo_preview.png"  transform="matrix(1 0 0 1 154 409)">
    </image>
</g>

Qt will complain about the missing "../logo_preview.png" file.

Hope this helps

Herald Smit
  • 2,342
  • 1
  • 22
  • 28