Results 1 to 4 of 4

Thread: QSvgRenderer not always working

  1. #1
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSvgRenderer not always working

    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.

  2. #2
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSvgRenderer not always working

    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).

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSvgRenderer not always working

    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.

  4. The following user says thank you to ChrisW67 for this useful post:

    BlandSauce (29th March 2010)

  5. #4
    Join Date
    Mar 2010
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSvgRenderer not always working

    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.

Similar Threads

  1. QSvgRenderer antialiasing
    By jonks in forum Qt Programming
    Replies: 4
    Last Post: 19th July 2013, 09:39
  2. QSvgRenderer undefined reference
    By TheJim01 in forum Newbie
    Replies: 3
    Last Post: 15th February 2010, 14:21
  3. QSvgRenderer and object's shape
    By Dusdan in forum Qt Programming
    Replies: 8
    Last Post: 3rd December 2007, 12:42
  4. QSvgRenderer bounds question
    By Gopala Krishna in forum Qt Programming
    Replies: 4
    Last Post: 30th November 2007, 19:33
  5. About QSvgRenderer
    By guher in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2007, 10:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.