0

i used following code to display the Svgz image

How to render a scaled SVG to a QImage?

My code:

QRect sSize=QApplication::desktop()->screenGeometry();
m_targetImage = QImage(sSize.width(),sSize.height(),QImage::Format_ARGB32);
...
QSvgRenderer *re =  new QSvgRenderer(":/Images/Green_Curls.svgz");
QPainter pai(&m_targetImage);
re->render(&pai);

i am getting following error:

error: C2668: 'QSvgRenderer::QSvgRenderer' : ambiguous call to overloaded function
c:\qt\qt5.0.0\5.0.0\msvc2010\include\qtsvg\qsvgrenderer.h(74): could be 'QSvgRenderer::QSvgRenderer(const QByteArray &,QObject *)'
c:\qt\qt5.0.0\5.0.0\msvc2010\include\qtsvg\qsvgrenderer.h(73): or       'QSvgRenderer::QSvgRenderer(const QString &,QObject *)'
while trying to match the argument list '(const char [26])'

i tried in google,but no luck :( how to solve this problem?

Community
  • 1
  • 1
Saravanan
  • 131
  • 2
  • 13
  • 1
    `new QSvgRenderer(QString(":/Images/Green_Curls.svgz"));` - I'm in the process of updating that answer right now :-) – Mat May 24 '13 at 07:38
  • Now i am getting following errors: dashboard.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QSvgRenderer::render(class QPainter *)" (__imp_?render@QSvgRenderer@@QAEXPAVQPainter@@@Z) referenced in function "protected: virtual void __thiscall DashBoard::paintEvent(class QPaintEvent *)" (?paintEvent@DashBoard@@MAEXPAVQPaintEvent@@@Z) – Saravanan May 24 '13 at 07:48
  • Oh, I didn't see svgZ. Not sure if Qt supports that. – Mat May 24 '13 at 07:49
  • dashboard.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QSvgRenderer::QSvgRenderer(class QString const &,class QObject *)" (__imp_??0QSvgRenderer@@QAE@ABVQString@@PAVQObject@@@Z) referenced in function "protected: virtual void __thiscall DashBoard::paintEvent(class QPaintEvent *)" (?paintEvent@DashBoard@@MAEXPAVQPaintEvent@@@Z) – Saravanan May 24 '13 at 07:49
  • 1
    That's a linker error (completely unrelated) - you're probably missing the QtSvg library in your linker setup (`QT += svg` would do it in a qmake .pro file) - no idea how to do that in Visual Studio if that's what you're doing, but please do search for that, it's probably been asked _a lot_. – Mat May 24 '13 at 07:52
  • Is there #include in the implementation file? – TheDarkKnight May 24 '13 at 07:53
  • Thanks Mat. i actually i put Include += svg. now i changed into QT += svg Problem solved and QT supporting the svgz file. – Saravanan May 24 '13 at 07:59

2 Answers2

2

Since both QByteArray and QString have constructors that take a const char* as its first argument, the compiler doesn't know which to choose.

Therefore you need to pass in either QString(":/Images/Green_Curls.svgz") if you want it to use the QString constructor, or QByteArray(":/Images/Green_Curls.svgz") for the QByteArray constructor.

TheDarkKnight
  • 27,181
  • 6
  • 55
  • 85
0

in Pro file:

QT += svg

Code:

   QSvgRenderer *re =  new QSvgRenderer(QString(":/Images/Green_Curls.svgz"));
   QPainter pai(&m_targetImage);
   re->render(&pai);
Saravanan
  • 131
  • 2
  • 13