Visual Studio Set-Up

Before going deep into creating the editor, we need to make sure everything is set up correctly.

What you’ll need:

Qt: Qt Open Source Download

VS Add-In: Visual Studio Add-In (2008 – 2013)

VS Add-In (VS2015): Visual Studio Add-In (2015)

Once you have installed Qt and the Visual Studio Add-In, open up visual studio and in the Qt tab, go to Qt Options and this window will appear:

2016-05-08 15_33_20-Qt Options

Make sure to add the Qt version that you installed, the image has the default paths for Qt.

Project Folder Structure

In my projects, I use premake to generate the project and solution files for Visual Studio. I do this for a few reasons, the scripts will automatically add all dependencies without needing to go through the project settings in Visual Studio. This also keeps my repository clean without storing the solution and project files and prevents the accidental inclusion of any build artifacts.

The folder structure that I’m using is like the image:

2016-05-08 16_21_24-QtEditor

The framework folder is where all your dependency files are located, essentially your library and header files.

The premake folder is where you put the premake executable and the premake scripts.

The Qt folder has the bin and lib folders from your Qt installation. You can remove any modules that you won’t be using. In my editor I only use Core, Gui, and Widgets.

The Resources folder is where you put all of your assets and files that your editor and/or game will be using.

The src folder is where all your source files are located. These files will need to be organized between your executables and libraries that you have defined in your premake script.

Once you run the build.bat file, another folder will be created called “visual_studio” and in it will have your build files, binaries and solution/project files. You don’t need to clean before building, if new files are added all that is needed is to run the build.bat file and the solution will be updated.

Using Premake

If you’re unfamiliar with premake, it is a command-line tool that is used to generate all of your project and solution files for visual studio. Premake uses lua scripts to configure your project and will need to be updated to work with Qt as well. I use batch files so even people who are not as tech-savvy can easily use premake.

You can download premake here: Premake5 Download

To use premake with Qt, you’ll need a special script as well to configure the project with all the Qt settings, I have a modified version of the file but the original version I found here: qt.lua For Premake

My modified version of the script is located on my GitHub page here: Premake Scripts

To highlight, the only thing that may need to be updated is this section in qt.lua:

-- Add any extra modules that you will use in your project --
modules = {
  core = {
    name = "Core",
    include = "Qt5Core",
    defines = { "QT_CORE_LIB" }
  gui = {
    name = "Gui",
    include = "Qt5Gui",
    defines = { "QT_GUI_LIB" }
  widgets = {
    name = "Widgets",
    include = "Qt5Widgets",
    defines = { "QT_WIDGETS_LIB" }

You can add or remove modules depending on which Qt modules you are using. On my GitHub page is an example premake5.lua script file that you can use to start with, most importantly you will need to include the qt.lua file like this:

-- Qt adjustments for premake
include "qt.lua"
local qt = premake.extensions.qt 

To update the project file, I register an executable with “Qt” as the language when it is a Qt project, which is used as a flag to run these lines:

-- Special section for Qt projects --
if proj.language == "Qt" then
  qtpath "../Qt"

  -- Update this for any other Qt modules you will be using
  qtmodules{ "core", "gui", "widgets" }
  qtprefix "Qt5"
  configuration { "Debug" }
  qtsuffix "d"
  configuration {}

This updates the project files with all the necessary Qt configurations and build configurations.

The only thing left is to create the batch files to build or clean the solution. These are really nice to have since not everyone is as comfortable using the console. The build.bat and clean.bat are located on my GitHub as well but they are:

Build File: .\premake\premake5.exe --file=.\premake\premake5.lua vs2015
Clean File: .\premake\premake5.exe --file=.\premake\premake5.lua clean

With this you should be ready to go creating your editor with Qt!