Qt Compilation - Using qmake on Windows

12,219

Install the visual studio addin (*) it detects the Q_OBJECT macro and handles all the extra build steps

If you want to use qmake it's described here, it's a nicer simpler format than regular makefiles and the VS addin-can convert between .pro files a visual studio solution.

(*) scroll down to other downloads, select version 1.1 for Qt4 or 1.2 for Qt 5

Share:
12,219
TJ Biddle
Author by

TJ Biddle

Lead DevOps Engineer for RateBeer.com @ ZX-Ventures

Updated on June 04, 2022

Comments

  • TJ Biddle
    TJ Biddle almost 2 years

    I'm having a bit of trouble trying to compile Qt programs under Windows. I'm on a work machine so I'm trying to be wary about what things I'm installing/setting up etc since I was given a procedure to follow originally to get this working (That didn't work), so please keep that mind.

    My development environment is normally Visual Studio on Windows 7. To install Qt I unzipped a few files into C:/Qt and setup my environmental variables to reflect it. I've written a short example file in Visual Studio and was able to have it compile; however things got tricky once I started using more than one file in the project.

    For example:

    Attempt 1 - Only had 1 .cpp file; ran 'qmake -tp vc projectname.pro' then went back into Visual Studio and loaded in the project, Built, and ran the file fine.

    Attempt 2 - Had the original .cpp file, added a .h & .cpp to reflect a popup dialog, ran 'qmake -tp vc projectname.pro', loaded in the project, and my two new files were gone.

    So two questions here:

    1) How do I have multiple files when working in Visual Studio?

    2) If I'm making a file from scratch just using notepad, how do I proceed? (ie: I make projectname.cpp, Use the designer to create the .ui file, run 'qmake -project' and 'qmake -tp vc projectname.pro' and the .ui file is not converted into the .h file as it's apparently supposed to do.

    Reading "C++ GUI Programming with Qt Second Edition (ISBN-13: 978-0-13-235416-5) if it's of any help.

    Thanks,

    Thomas

  • TJ Biddle
    TJ Biddle over 12 years
    Thanks, that solved the first issue at least! I ended up adding the header file to the .pro file. I gave the add-in a try, but ended up uninstalling it as it was conflicting with my currently dev. environment. Our Senior Engineer was able to explain how the compilation works with our projects though. I might give the addin another try on personal projects in the future.
  • John McLear
    John McLear about 11 years
    qt.nokia.com/downloads/visual-studio-add-in no longer directs to the visual studio addin
  • Tom Fenech
    Tom Fenech over 8 years
    The second link in this answer is also broken.