Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Problem when using Libtorch with Qt
Forum Updated to NodeBB v4.3 + New Features

Problem when using Libtorch with Qt

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
9 Posts 3 Posters 1.9k Views 1 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.
  • Z Offline
    Z Offline
    ZINE
    wrote on 9 Jun 2023, 14:52 last edited by ZINE 6 Sept 2023, 14:53
    #1

    Hi all,

    I would like to use the PyTorch C++ distribution "libtorch" with my Qt application. I have Qt 5.9.5 and Ubuntu 18.04.
    First, I downloaded and unzipped the libtorch library using the below Pytorch selection.

    f70c5dfc-b7ed-4560-a332-bb538203e230-image.png

    Then, I created a basic Qt application where I added the necessary flags and library paths in the .pro file, as shown below.

    196c3a77-9e89-41cb-9fb2-9dac9f947152-Screenshot from 2023-06-09 22-45-28.png
    17399939-4beb-4032-a0c2-449cd96c81a9-Screenshot from 2023-06-09 22-46-04.png

    I build and run the basic code below:
    26900237-8dbd-49e5-a915-f38f46c5ca27-Screenshot from 2023-06-09 22-49-13.png

    However, I got the following errors:
    a0380cac-7b92-4098-a596-49a5f3aae36c-Screenshot from 2023-06-09 22-50-03.png

    What is the issue because I consider that I added all the necessary flags and paths ??

    S 1 Reply Last reply 9 Jun 2023, 18:14
    0
    • Z ZINE
      9 Jun 2023, 14:52

      Hi all,

      I would like to use the PyTorch C++ distribution "libtorch" with my Qt application. I have Qt 5.9.5 and Ubuntu 18.04.
      First, I downloaded and unzipped the libtorch library using the below Pytorch selection.

      f70c5dfc-b7ed-4560-a332-bb538203e230-image.png

      Then, I created a basic Qt application where I added the necessary flags and library paths in the .pro file, as shown below.

      196c3a77-9e89-41cb-9fb2-9dac9f947152-Screenshot from 2023-06-09 22-45-28.png
      17399939-4beb-4032-a0c2-449cd96c81a9-Screenshot from 2023-06-09 22-46-04.png

      I build and run the basic code below:
      26900237-8dbd-49e5-a915-f38f46c5ca27-Screenshot from 2023-06-09 22-49-13.png

      However, I got the following errors:
      a0380cac-7b92-4098-a596-49a5f3aae36c-Screenshot from 2023-06-09 22-50-03.png

      What is the issue because I consider that I added all the necessary flags and paths ??

      S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 9 Jun 2023, 18:14 last edited by
      #2

      Hi,

      Did you first try to build the torch example described here ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Z 1 Reply Last reply 9 Jun 2023, 18:33
      0
      • S SGaist
        9 Jun 2023, 18:14

        Hi,

        Did you first try to build the torch example described here ?

        Z Offline
        Z Offline
        ZINE
        wrote on 9 Jun 2023, 18:33 last edited by
        #3

        @SGaist Yes I build this example successfully using CMAKE.

        S 1 Reply Last reply 9 Jun 2023, 18:43
        0
        • Z ZINE
          9 Jun 2023, 18:33

          @SGaist Yes I build this example successfully using CMAKE.

          S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 9 Jun 2023, 18:43 last edited by
          #4

          @ZINE then I would recommend to keep using CMake and build your Qt project with it especially since qmake has been deprecated with Qt 6.

          Otherwise, check the flags used by cmake. Also note that the example uses C++14, something that you did not activate in your qmake project.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          C Z 2 Replies Last reply 9 Jun 2023, 19:00
          0
          • S SGaist
            9 Jun 2023, 18:43

            @ZINE then I would recommend to keep using CMake and build your Qt project with it especially since qmake has been deprecated with Qt 6.

            Otherwise, check the flags used by cmake. Also note that the example uses C++14, something that you did not activate in your qmake project.

            C Online
            C Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 9 Jun 2023, 19:00 last edited by
            #5

            Which of these two torch libs did you download? According to your pro-file (QMAKE_CXXFLAGS += -DGLIBCXX_USE_CXX_ABI=0) it must be the first one (Pre-cxx11 ABI)

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            Z 1 Reply Last reply 9 Jun 2023, 20:02
            0
            • S SGaist
              9 Jun 2023, 18:43

              @ZINE then I would recommend to keep using CMake and build your Qt project with it especially since qmake has been deprecated with Qt 6.

              Otherwise, check the flags used by cmake. Also note that the example uses C++14, something that you did not activate in your qmake project.

              Z Offline
              Z Offline
              ZINE
              wrote on 9 Jun 2023, 19:49 last edited by
              #6

              @SGaist I build similar example that uses C++ 17 and it works fine with CMake.

              How to activate C++14 in the qmake project ?

              How to use CMake to build a Qt project ? Is there a way in Qt to automate the creation of CMakeLists.txt (packages, sources ...etc) and use CMake to build Qt project ?

              1 Reply Last reply
              0
              • C Christian Ehrlicher
                9 Jun 2023, 19:00

                Which of these two torch libs did you download? According to your pro-file (QMAKE_CXXFLAGS += -DGLIBCXX_USE_CXX_ABI=0) it must be the first one (Pre-cxx11 ABI)

                Z Offline
                Z Offline
                ZINE
                wrote on 9 Jun 2023, 20:02 last edited by
                #7

                @Christian-Ehrlicher Yes, it is the first one that I used.

                C 1 Reply Last reply 9 Jun 2023, 20:23
                0
                • Z ZINE
                  9 Jun 2023, 20:02

                  @Christian-Ehrlicher Yes, it is the first one that I used.

                  C Online
                  C Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on 9 Jun 2023, 20:23 last edited by
                  #8

                  @ZINE But why? Remove this crappy define and use the correct lib with correct cxxabi support.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  Z 1 Reply Last reply 12 Jun 2023, 05:07
                  0
                  • C Christian Ehrlicher
                    9 Jun 2023, 20:23

                    @ZINE But why? Remove this crappy define and use the correct lib with correct cxxabi support.

                    Z Offline
                    Z Offline
                    ZINE
                    wrote on 12 Jun 2023, 05:07 last edited by
                    #9

                    It works when I select libtorch that supports cxxabi and delete the define in the .pro file:
                    #QMAKE_CXXFLAGS += -DGLIBCXX_USE_CXX11_ABI=0.

                    Thank you @Christian-Ehrlicher.

                    1 Reply Last reply
                    0
                    • Z ZINE has marked this topic as solved on 12 Jun 2023, 05:07

                    1/9

                    9 Jun 2023, 14:52

                    • Login

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