Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QtSvg on Linux doesn't work
Forum Updated to NodeBB v4.3 + New Features

QtSvg on Linux doesn't work

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 805 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sucharek
    wrote on last edited by
    #1

    Hi, I'm developing an application on Windows and Linux, but when I try to build it on Linux, I have a problem. I'm using svg files, which work fine on Windows, but when I try to run it on Linux, it doesn't work. I checked the files and all seems to be good. I don't know why it doesn't work.

    JonBJ KroMignonK 2 Replies Last reply
    0
    • S Sucharek

      Hi, I'm developing an application on Windows and Linux, but when I try to build it on Linux, I have a problem. I'm using svg files, which work fine on Windows, but when I try to run it on Linux, it doesn't work. I checked the files and all seems to be good. I don't know why it doesn't work.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @Sucharek
      I use QtSvg under Ubuntu 20.04 and it works fine.

      Nobody can help further from your statements like

      but when I try to run it on Linux, it doesn't work

      1 Reply Last reply
      1
      • S Sucharek

        Hi, I'm developing an application on Windows and Linux, but when I try to build it on Linux, I have a problem. I'm using svg files, which work fine on Windows, but when I try to run it on Linux, it doesn't work. I checked the files and all seems to be good. I don't know why it doesn't work.

        KroMignonK Offline
        KroMignonK Offline
        KroMignon
        wrote on last edited by
        #3

        @Sucharek said in QtSvg on Linux doesn't work:

        I checked the files and all seems to be good. I don't know why it doesn't work.

        Very hard to help you with this description!
        Work's for me (™)

        One tip: did you check filename case... Linux file system is case-sensitive

        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sucharek
          wrote on last edited by Sucharek
          #4

          Hi, I forgot to add an important detail. I'm on Arch. I installed the qt5 package on Arch.
          EDIT: Some more info: 5.10.79-1-MANJARO

          1 Reply Last reply
          0
          • S Offline
            S Offline
            Sucharek
            wrote on last edited by Sucharek
            #5

            Hi, so I fixed it. I initialized the svg file paths when declaring the variable, and that works on Windows, but for some reason not on Linux. I had:

            QGraphicsSvgItem *svg = new QGraphicsSvgItem("path/to/svg.svg");
            

            on the top, but that doesn't work. I only had to add:

            QGraphicsSvgItem *svg;
            

            at the top, and declare it in the void that has "ui->setupUi(this);" in it (don't know what's the name of that part):

            ui->setupUi(this);
            svg = new QGraphicsSvgItem("path/to/svg.svg");
            
            JonBJ 1 Reply Last reply
            0
            • S Sucharek

              Hi, so I fixed it. I initialized the svg file paths when declaring the variable, and that works on Windows, but for some reason not on Linux. I had:

              QGraphicsSvgItem *svg = new QGraphicsSvgItem("path/to/svg.svg");
              

              on the top, but that doesn't work. I only had to add:

              QGraphicsSvgItem *svg;
              

              at the top, and declare it in the void that has "ui->setupUi(this);" in it (don't know what's the name of that part):

              ui->setupUi(this);
              svg = new QGraphicsSvgItem("path/to/svg.svg");
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Sucharek said in QtSvg on Linux doesn't work:

              on the top

              Assuming that means "at the top of a source file, outside of any method" you should never create a new QGraphicsSvgItem there (nor more or less any Qt UI object). Your statement will execute before you have created the QApplication in your main(), and until then it is undefined behaviour to create any such UI object. You are "lucky" it worked in Windows at all.

              Also, for the record, does your "path/to/svg.svg" imply this is a relative path? Paths to such files should always be absolute (or in Qt resources).

              S Pablo J. RoginaP 2 Replies Last reply
              2
              • JonBJ JonB

                @Sucharek said in QtSvg on Linux doesn't work:

                on the top

                Assuming that means "at the top of a source file, outside of any method" you should never create a new QGraphicsSvgItem there (nor more or less any Qt UI object). Your statement will execute before you have created the QApplication in your main(), and until then it is undefined behaviour to create any such UI object. You are "lucky" it worked in Windows at all.

                Also, for the record, does your "path/to/svg.svg" imply this is a relative path? Paths to such files should always be absolute (or in Qt resources).

                S Offline
                S Offline
                Sucharek
                wrote on last edited by
                #7

                Hi @JonB, thats for telling me. I never knew, and used it in almost every of my project. I'll keep an eye on that.
                And yes, I used resources for the svg image.

                1 Reply Last reply
                0
                • JonBJ JonB

                  @Sucharek said in QtSvg on Linux doesn't work:

                  on the top

                  Assuming that means "at the top of a source file, outside of any method" you should never create a new QGraphicsSvgItem there (nor more or less any Qt UI object). Your statement will execute before you have created the QApplication in your main(), and until then it is undefined behaviour to create any such UI object. You are "lucky" it worked in Windows at all.

                  Also, for the record, does your "path/to/svg.svg" imply this is a relative path? Paths to such files should always be absolute (or in Qt resources).

                  Pablo J. RoginaP Offline
                  Pablo J. RoginaP Offline
                  Pablo J. Rogina
                  wrote on last edited by
                  #8

                  @Sucharek as @JonB pointed out, the placement "at the top fo source file" is not a good idea.

                  Given that you have these statements:

                  ui->setupUi(this);
                  svg = new QGraphicsSvgItem("path/to/svg.svg");

                  which implies some kind of constructor for a widget, you may want to add svg as a member of that widget class (in the class header file):

                  ...
                  private:
                  ...
                  QGraphicsSvgItem *svg;
                  ...
                  

                  then in the constructor you could do:

                  ui->setupUi(this);
                  svg = new QGraphicsSvgItem("path/to/svg.svg", this);
                  

                  to take advantage of Qt's memory management feature
                  (in your example, you must delete the svg object yourself...)

                  Upvote the answer(s) that helped you solve the issue
                  Use "Topic Tools" button to mark your post as Solved
                  Add screenshots via postimage.org
                  Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  2

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved