Creating Qt5 projects on Ubuntu with Visual Studio

This tutorial shows how to create, build and debug a simple Qt5 project on a Kubuntu machine using Visual Studio.

Before you begin, make sure that VisualGDB 4.1 or later is installed.

  1. Start Visual Studio. Start creating a new project using the Linux Project Wizard from VisualGDB folder:01-qtubuntu
  2. On the first wizard page select “A QT-based application”:02-newapp
  3. On the next page specify the Ubuntu machine that you want to target. Note that the machine should have an SSH server installed and running:03-machine
  4. By default VisualGDB will generate a QT4-based project. To switch it to QT5 click “configure QT settings” and select “QT5″ from the list:04-qt5
  5. Press “Next”. VisualGDB will check you QT5 installation and , VisualGDB will offer installing it automatically:05-installqtIf the automatic installation fails, run the following commands on your Ubuntu machine to install it manually:
  6. After checking/installing QT5 VisualGDB will test other tools necessary to build your project:06-test
  7. On the last wizard page you can setup the method that will be used to synchronize source files between your Windows and Ubuntu machines. If you keep the default settings the sources will be stored on the Windows machine and the modified files will be automatically uploaded on each build:07-sources
  8. Press Finish to let the wizard create a project for you. VisualGDB will automatically create a local copy of include directories from the Ubuntu machine and make them available to IntelliSense:08-qtincludes
  9. Build your project by pressing Ctrl-Shift-B. Note how the sources are uploaded to the Ubuntu machine and built there:09-build
  10. Set a breakpoint in ButtonClicked() and press F5 to begin debugging. The application will be stared on the Ubuntu machine and its windows will be displayed on the development machine via XMing X server. Click at the button to trigger your breakpoint:10-break
  11. When done debugging, note that IntelliSense does not recognize the ui_MainWindow.h file. This happens because the file is generated during the build process and is only present on the Ubuntu machine. We will fix it by adding a custom build action that will download the generated files after build. Right-click on your project in Solution Explorer and select VisualGDB Project Properties, then go to the Custom Build Steps page:11-custom
  12. Click “edit” near the “actions after building” list, then click “add”. Select “download a directory from a remote computer” and enter the following settings:
    Remote computer Your Ubuntu machine
    Remote directory $(BuildDir)/$(ConfigurationName)
    Local directory $(ProjectDir)\$(ConfigurationName)


  13. Press OK to add action to the post-build action list:13-list
  14. Build your project and reload it. Select the setupUi() call, right-click on it and select “Go to Definition”. Note how Visual Studio opens the generated ui_MainWindow.h file that was downloaded from the Ubuntu machine:14-uifile