PDA

View Full Version : QSvgRenderer not always working



BlandSauce
27th March 2010, 05:43
This might be more of a Linux problem than a Qt problem, but I'm not sure.
Currently, I have a simple program that should be placing a SVG image of a spaceship in the center of a scene. I developed it in Windows, but it needed to work in Linux to meet the assignment requirements.
When running it in Windows, it works as expected, but running it on my dual-booted Ubuntu, the svg image is not rendered, but there is also no errors.
I thought maybe it was something to do with Linux in general, but the computers at school run it as expected, as well.
The most relevant code:
#include "ship.h"

#include <QPainter>
#include <QSvgRenderer>

Ship::Ship( qreal x, qreal y ) : QGraphicsSvgItem()
{
// set Station pixmap and position
setPos( x, y );
this->setFlags(QGraphicsItem::ItemClipsToShape);
this->setCacheMode(QGraphicsItem::NoCache);
this->setZValue(0);
renderer()->load(QString(":/img/ship01.svg"));
}

void Ship::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
painter->setRenderHint( QPainter::Antialiasing );
painter->setPen( QPen( Qt::black, 2 ) );
painter->drawRect( -5, -10, 11, 20 );
painter->drawLine( -5, -10, 0, -15 );
painter->drawLine( 5, -10, 0, -15 );
painter->drawLine( 6, 0, 11, 0 );
painter->drawLine( -10, 0, -5, 0 );
painter->drawLine( -10, -10, -10, 10 );
painter->drawLine( 11, -10, 11, 10 );

//renderer()->load(QString(":/img/ship01.svg"));
renderer()->render(painter,QRectF(QPoint(-32,-32), QSize(64,64))); //should display svg ship

}

In Windows on my computer and Ubuntu on the school computers, the larger SVG image is placed over the manual line drawing, but on my Ubuntu, only the ugly little line drawing shows up (I placed it there as backup, just to have something drawn).

Possibly pertinent information:
I'm running Windows 7, and I installed Qt SDK on Thursday; and wrote my program and had it run successfully with the svg image.
I then installed Qt Creator in Ubuntu 9.10 on the same computer through the add applications tool in the applications menu, which I later found out to be an earlier version of Qt Creator. I have since installed Qt SDK from the Nokia site, as I did for Windows, but my program still doesn't work correctly.
The computers at school are running Ubuntu 8.04, which I installed Qt SDK on this morning from the Nokia download. My program works correctly on them.

All I can think may be the problem is old libraries installed with the older version of Qt Creator, but I would assume the second installation with the newer version would have replaced anything from that. Also, i would expect an error of some sort if there were old libs that couldn't handle it.
Also, I thought it might be graphics card related, but I already uninstalled my drivers and tested again. (And then had loads of fun getting them reinstalled)

Any pointers in the right direction would be appreciated. I'm pretty sure I can finish development in Windows, but it's nice to be able to double check in Linux, and also I'd just like to get things running correctly anyway.

BlandSauce
28th March 2010, 19:29
Just an update on this. It seems the problem lies with my svg files or how they're read somehow.
After doing dome more work on it, I tested in linux again, and while the ship image still doesn't show up, my "asteroid" image at least appeared, but it was incorrect. It should be a rough hexagon with three smaller rough shaped on it, but it showed up as a much smaller triangle. Also, an svg file that was only a red circle displayed correctly, as did a 3d pie chart I pulled off the internet.
All of them that I have made were done in Inkscape (including the red circle that works).

ChrisW67
28th March 2010, 23:42
You should check that your application, when run, is picking up the correct set of Qt libraries, i.e. the libraries in the "qt/lib" subdirectory of the SDK install and not a system set. You can try the "ldd" Linux command to help with this.

BlandSauce
29th March 2010, 04:08
Ok, It's working now.
I had to add the install folder as a Qt version, then choose that version to run it with.
Now I just have a problem with QTimer. :P

Thanks for the point in the right direction.