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. Creating a Qt static c++ library for non-Qt c++ application
Forum Updated to NodeBB v4.3 + New Features

Creating a Qt static c++ library for non-Qt c++ application

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 3 Posters 1.1k 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
    sasanka
    wrote on last edited by
    #1

    Hello,
    I created a static library in Qt 5.11 i have successfully generated lib.a and header file and used them in a Qt C++ project. Everything works fine.
    Once i create a Non-Qt C++ project and include the library and header file, i get a compilation error " Qobject no such file or directory."

    Is there a way to create Qt static library for C++ (Non-Qt) application. I would later want to share this library for C++ application developed using Visual Studio/Other IDE.

    Christian EhrlicherC 1 Reply Last reply
    0
    • S sasanka

      Hello,
      I created a static library in Qt 5.11 i have successfully generated lib.a and header file and used them in a Qt C++ project. Everything works fine.
      Once i create a Non-Qt C++ project and include the library and header file, i get a compilation error " Qobject no such file or directory."

      Is there a way to create Qt static library for C++ (Non-Qt) application. I would later want to share this library for C++ application developed using Visual Studio/Other IDE.

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You need the Qt headers when you include them in your library headers.
      And there are very few Qt classes which work without a Qt event loop and even less working without a QCoreApplication.

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sasanka
        wrote on last edited by
        #3

        I am only going to use the Network , QT core modules.

        Christian EhrlicherC 1 Reply Last reply
        0
        • S sasanka

          I am only going to use the Network , QT core modules.

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @sasanka said in Creating a Qt static c++ library for non-Qt c++ application:

          I am only going to use the Network , QT core modules

          This does not matter. Esp. the network module needs a running event loop.

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

          S 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            @sasanka said in Creating a Qt static c++ library for non-Qt c++ application:

            I am only going to use the Network , QT core modules

            This does not matter. Esp. the network module needs a running event loop.

            S Offline
            S Offline
            sasanka
            wrote on last edited by
            #5

            @Christian-Ehrlicher
            I built a static version of Qt 5.12.12 from the sources. I was also able to use this static build to compile the sources. But even after i created a static library out of this and when i am trying to include this library in a Non-Qt C++ project. I get compilation issues that displays QObject no found.

            So is there a procedure to use a custom made Qt Library for Non-Qt based C++ project.
            If so could you point me out how i could achieve it.

            Christian EhrlicherC 1 Reply Last reply
            0
            • S sasanka

              @Christian-Ehrlicher
              I built a static version of Qt 5.12.12 from the sources. I was also able to use this static build to compile the sources. But even after i created a static library out of this and when i am trying to include this library in a Non-Qt C++ project. I get compilation issues that displays QObject no found.

              So is there a procedure to use a custom made Qt Library for Non-Qt based C++ project.
              If so could you point me out how i could achieve it.

              Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Sometimes I wonder if the people really read what we're writing...
              If you have an header which includes QObject header file and want to use it in another library you have to provide the QObject header file there too. If you don't want this then don't include QObject in your header which basically means - don't use Qt at all.
              This has nothing to do if a library is compiled static or shared - it's a basic thing - if you want to use a library you have to make sure you have access to all dependencies during built and runtime.

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

              SGaistS 1 Reply Last reply
              1
              • Christian EhrlicherC Christian Ehrlicher

                Sometimes I wonder if the people really read what we're writing...
                If you have an header which includes QObject header file and want to use it in another library you have to provide the QObject header file there too. If you don't want this then don't include QObject in your header which basically means - don't use Qt at all.
                This has nothing to do if a library is compiled static or shared - it's a basic thing - if you want to use a library you have to make sure you have access to all dependencies during built and runtime.

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Christian-Ehrlicher or use the pimple idiom but that can make things pretty complicated depending on what the library originally offers as API.

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

                Christian EhrlicherC 1 Reply Last reply
                0
                • SGaistS SGaist

                  @Christian-Ehrlicher or use the pimple idiom but that can make things pretty complicated depending on what the library originally offers as API.

                  Christian EhrlicherC Online
                  Christian EhrlicherC Online
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @SGaist This will not work as the op exports a class derived from Qt (at least this is my guess) but yes, this can be an option. But as already discussed there are only a few Qt classes which work without a Q(Core)Application or a running event loop.
                  You can abstract this all away and add a wrapper class which convrts between Qt and plain c++ but this is cumbersome and still does not fix the event loop problem.

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

                  SGaistS 1 Reply Last reply
                  0
                  • Christian EhrlicherC Christian Ehrlicher

                    @SGaist This will not work as the op exports a class derived from Qt (at least this is my guess) but yes, this can be an option. But as already discussed there are only a few Qt classes which work without a Q(Core)Application or a running event loop.
                    You can abstract this all away and add a wrapper class which convrts between Qt and plain c++ but this is cumbersome and still does not fix the event loop problem.

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @Christian-Ehrlicher said in Creating a Qt static c++ library for non-Qt c++ application:

                    @SGaist This will not work as the op exports a class derived from Qt (at least this is my guess) but yes, this can be an option. But as already discussed there are only a few Qt classes which work without a Q(Core)Application or a running event loop.
                    You can abstract this all away and add a wrapper class which convrts between Qt and plain c++ but this is cumbersome and still does not fix the event loop problem.

                    100% agreed, it was just to propose a possible solution but it clearly makes things more complicated that way.

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

                    1 Reply Last reply
                    0

                    • Login

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