Featured Photo by Guillaume Bourdages on Unsplash

QT “Hello, world” on Windows 10

Erich Izdepski
Oct 11 · 5 min read

Getting Cute

Writing desktop apps is almost an oddity these days, since everything is so web-centric. In fact, web development tools and techniques have even moved into the desktop space as first-class citizens, with the help of projects like electronjs. However, there are still very good tools out there for writing apps that need a little more power. QT is one of them. If your company is working on apps, have a look at QT. It can also support mobile application development and it can leverage C++ and Python coders.

I am doing a very simple task- running “Hello, world” using the QT environment on Windows 10. The QT development environment for Windows and other platforms is available here: https://doc-snapshots.qt.io/qt5-5.12/gettingstarted.html

I am using the open source LGPL version for Windows 10 and specifically looking at UWP applications (see https://docs.microsoft.com/en-us/windows/uwp/get-started/universal-application-platform-guide )

After you spend an hour or two downloading QT 5.x for Windows and try to run your first program it will probably fail. NOTE: I am bad and didn’t read the manual. If you read the manual, good on you! You can stop here, unless it still didn’t work for you…

Neither the install process nor the QT Creator wizard help enough with setting up your development environment properly when you create a new project or launch a sample one.

I tried to build the example app “Hello tr() example” and it failed. The first error was:

Project ERROR: Windows SDK 10.0 requested by mkspec is not installed.

To write an app for Windows 10 UWP (Universal Windows Platform), you need a new SDK, not the usual Microsoft Visual C++ Runtime. You can get it from https://developer.microsoft.com/en-us/windows/downloads/windows-10-sdk

The Microsoft installer worked perfectly and when I rebuilt my QT sample app, it worked — an executable was in the debug directory. Trying to run the app you just built, though, leads to the next problem:

12:52:36: No executable to deploy found in .
Error while building/deploying project hellotr (kit: Qt 5.12.5 for UWP 64bit (MSVC 2015))
When executing step "Run windeployqt"

This is pretty annoying. Notice the error says "No executable to deploy found in ." - it leaves out the directory! Something is very wrong.

Pressing the Run button will build/deploy/run your project, but if the build fails, you are out of luck. My build process said it executed normally. I tried the "Deploy Project hellotr" option, and it complained there was no executable to deploy. So what exactly did the build process build? I looked at the output and saw it should be creating hellotr.exe so I searched for it and found it in this folder:

F:\qt\Examples\Qt-5.12.5\linguist\build-hellotr-Qt_5_12_5_for_UWP_64bit_MSVC_2015-Debug\debug

The executable will not run, though, since the QT dll's are missing from the debug folder. I changed to a release configuration and re-built the project. This time I did get a directory with the QT dll's but now the Microsoft dll's are missing.

Execution errors

Eureka!

I cleaned all, rebuilt, deployed, ran and still got errors so decided to pursue these new ones since they look much more useful.

Environment Variable Problem- the key issue

I found a message on Stack Overflow that was helpful for fixing the environment variable problem. First, set the missing environment variable. Second, enable Windows 10 Developer Mode through the Settings app. Nothing in the error messages about that- not very helpful messages!

Setting Build Environment Properties

I needed to set the value of ExtensionSdkDir in QT Creator. The value on my machine is:

C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs

You have to click Projects and then add the variable to the Build Environment.

Note new environment variable name/value in bold

Then you have to turn on Windows 10 Developer Mode.

Windows 10 Developer Mode

Run the app again from QT Creator- it should finally run. Hopefully this will help you get started faster than me!

Deployment

Just getting the app to run from within QT is not enough. If you click on the exe file created you will still see some errors about missing dll files. Selecting “Deploy” does NOT create an actual deployable application. It only runs within QT Creator. Crazy, huh?

What’s missing? vcruntime140_APP.dll and MSVCP140_APP.dll

You cannot just copy these from your system and hope they work. You will get various other errors or no output/app window at all.

The solution to this mess is create a static application with all required libraries built in. This creates a big app. Sorry. Here are the non-trivial instructions:

https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW

Help with these static build instructions is outside the scope of this article, but the information here will get you pointed in the right direction. I will say I am running the instructions as I write this, so you could ask some questions and I may have the answer. Oops- the script for creating the static build environment just failed. Guess that will be another post!

Erich Izdepski

Written by

Software engineer and architect who’s built web, mobile and desktop apps in multiple industries over a span of more than 22 years. CTO @ BTS Software Solutions.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade