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. What paths/libs to include when using Qt static in Visual Studio?
Forum Updated to NodeBB v4.3 + New Features

What paths/libs to include when using Qt static in Visual Studio?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 2.2k 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.
  • A Offline
    A Offline
    Armux
    wrote on 18 May 2021, 21:22 last edited by
    #1

    Hello, guys :)

    I compiled Qt 5 source to use it staticaly in my program. The thing is: I want to code my program in Visual Studio (so i downloaded Qt Visual Studio Tools extension). After, I created a new project in VS of type "Qt Widgets Application". Until now okay, all worked and I dont need to include nothing manually.

    Buuuut a different case is: If I want to add a new form MANUALLY in an existing project (let's say I have a Visual Studio empty project)? In fact, I know how to add the form, but when I try to compile, it shows lots of logs for "unresolved external symbol" and these things...

    I already tried to make some includes for paths/libs from Qt in my project configuration, but it still showing me errors of this type (unresolved external symbols).

    How can I discover the correct paths/libs to include in my Visual Studio project configuration? So i can add Qt forms manually and fix my problem.

    Thanks for any help =)

    1 Reply Last reply
    0
    • C Online
      C Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on 18 May 2021, 22:42 last edited by
      #2

      It's a bit more complicated than just adding paths. Qt uses code generation tools: moc, qrc and uic for the metaobject system, resources and widget code. Those tools generate code that you need to include in your project, compile and link.

      That having said what you need to do is

      • Add Qt include paths to your project. This means for every Qt module used, so for example if you have Qt installed in C:\Qt\ and want to use core, gui and widgets modules you'd include C:\Q:\include\QtCore, C:\Q:\include\QtGui and C:\Q:\include\QtWidgets
      • Same goes for libraries. You need to add libraries path like C:\Qt\lib and then a library for each module you use, so Qt5Core.lib, Qt5Gui.lib and Qt5Widgets.lib. These are for Release configuration. For debug those will have a d postfix, so Qt5Cored.lib and so on.
      • Every .h file containing a QObject derived class needs to be run through moc, so you'd need to write a custom build step for those files and then include the output file in your project. Similarly for .qrc and .ui files.

      Those steps, especially the last one, will quickly become extremely tedious to do manually, so it's a lot (and I mean a lot) easier to use the extension. It does all that work for you. If you have an existing project it's a bit of manual work to convert it to a "Qt aware" one, but it's doable. Open the .vcxproj file of your project in a text editor and fond the <Keyword> key in the "Globals" PropertyGroup. Change its value to be QtVS_v304. After that reopen the project in VS and go to
      Extensions->Qt VS Tools->Convert custom build steps to Qt/MSBuild. After that you can go to project's settings and in the Qt Project Settings set up all you need - Qt version, used modules etc.

      A 1 Reply Last reply 18 May 2021, 23:08
      3
      • C Chris Kawa
        18 May 2021, 22:42

        It's a bit more complicated than just adding paths. Qt uses code generation tools: moc, qrc and uic for the metaobject system, resources and widget code. Those tools generate code that you need to include in your project, compile and link.

        That having said what you need to do is

        • Add Qt include paths to your project. This means for every Qt module used, so for example if you have Qt installed in C:\Qt\ and want to use core, gui and widgets modules you'd include C:\Q:\include\QtCore, C:\Q:\include\QtGui and C:\Q:\include\QtWidgets
        • Same goes for libraries. You need to add libraries path like C:\Qt\lib and then a library for each module you use, so Qt5Core.lib, Qt5Gui.lib and Qt5Widgets.lib. These are for Release configuration. For debug those will have a d postfix, so Qt5Cored.lib and so on.
        • Every .h file containing a QObject derived class needs to be run through moc, so you'd need to write a custom build step for those files and then include the output file in your project. Similarly for .qrc and .ui files.

        Those steps, especially the last one, will quickly become extremely tedious to do manually, so it's a lot (and I mean a lot) easier to use the extension. It does all that work for you. If you have an existing project it's a bit of manual work to convert it to a "Qt aware" one, but it's doable. Open the .vcxproj file of your project in a text editor and fond the <Keyword> key in the "Globals" PropertyGroup. Change its value to be QtVS_v304. After that reopen the project in VS and go to
        Extensions->Qt VS Tools->Convert custom build steps to Qt/MSBuild. After that you can go to project's settings and in the Qt Project Settings set up all you need - Qt version, used modules etc.

        A Offline
        A Offline
        Armux
        wrote on 18 May 2021, 23:08 last edited by
        #3

        @Chris-Kawa

        I will analyze what i can do based in your reply. Your first hints (about what to include), was basically what I've made, I just "ignored" the third point about:

        • Every .h file containing a QObject derived class needs to be run through moc, so you'd need to write a custom build step for those files and then include the output file in your project. Similarly for .qrc and .ui files.

        Can you explain me more about it? Or give me a link where I can learn? (Im not a very experienced user)

        Those steps, especially the last one, will quickly become extremely tedious to do manually, so it's a lot (and I mean a lot) easier to use the extension. It does all that work for you. If you have an existing project it's a bit of manual work to convert it to a "Qt aware" one, but it's doable. Open the .vcxproj file of your project in a text editor and fond the <Keyword> key in the "Globals" PropertyGroup. Change its value to be QtVS_v304. After that reopen the project in VS and go to

        Extensions->Qt VS Tools->Convert custom build steps to Qt/MSBuild. After that you can go to project's settings and in the Qt Project Settings set up all you need - Qt version, used modules etc.

        I will make tests with it too.

        Thanks for your help :D

        C 1 Reply Last reply 18 May 2021, 23:37
        0
        • A Armux
          18 May 2021, 23:08

          @Chris-Kawa

          I will analyze what i can do based in your reply. Your first hints (about what to include), was basically what I've made, I just "ignored" the third point about:

          • Every .h file containing a QObject derived class needs to be run through moc, so you'd need to write a custom build step for those files and then include the output file in your project. Similarly for .qrc and .ui files.

          Can you explain me more about it? Or give me a link where I can learn? (Im not a very experienced user)

          Those steps, especially the last one, will quickly become extremely tedious to do manually, so it's a lot (and I mean a lot) easier to use the extension. It does all that work for you. If you have an existing project it's a bit of manual work to convert it to a "Qt aware" one, but it's doable. Open the .vcxproj file of your project in a text editor and fond the <Keyword> key in the "Globals" PropertyGroup. Change its value to be QtVS_v304. After that reopen the project in VS and go to

          Extensions->Qt VS Tools->Convert custom build steps to Qt/MSBuild. After that you can go to project's settings and in the Qt Project Settings set up all you need - Qt version, used modules etc.

          I will make tests with it too.

          Thanks for your help :D

          C Online
          C Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on 18 May 2021, 23:37 last edited by Chris Kawa
          #4

          @Armux said:

          Can you explain me more about it?

          When you have a class like this:

          class Something : public QObject
          {
             Q_OBJECT
          signals:
             void whatever() const;
          };
          

          you need to run this header through moc (Meta-Object Compiler). It's a tool located in Qt's installation bin directory. It generates a .cpp file with implementation of the signals and the meta object stuff for the class that the Q_OBJECT macro signifies.
          Similarly, for form .ui files you need to run them through uic (UI Compiler) tool, also located in Qt's bin directory. This again generates a C++ file that you need to include in your project. The third Qt tool is rcc (Resource Compiler) used on .qrc files that also generates C++ code files to include.

          Or give me a link where I can learn?

          More info on these tools and how to use them: moc, uic and rcc.

          You could run them manually, but it's not practical. What you want to do is run them every time the source files change or you rebuild your solution. In VS projects this can be achieved by specifying custom build steps. You'd define a pre-build step for .ui file to run the uic tool and then mark the output as source file, so that it is treated as part of the project. Qt extension goes a bit further and specifies custom project property pages to automate this process more.

          If you want to learn how all this works you can generate a simple Qt project with a wizard and analyze project and property page files it creates, but I'll warn you upfront that it's complicated.

          Setting all this up is a pretty laborious process when done manually. If you're new to this I would strongly discourage you from going this path until you get a better hang on Qt's build process. The concept itself is pretty easy - you just run some source files through Qt tools and include them in the build. It's one or two additional commands when building a single file from command line, but setting this up in a maintainable way in a VS project with many files can get hairy fast. It's a lot easier to stick to the extension that takes care of all of this stuff for you and exposes Qt specific project settings with a nice ui within VS.

          1 Reply Last reply
          2

          1/4

          18 May 2021, 21:22

          • Login

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