Installing QT-Creator on Windows Platform

Qtcreator is probably the best C++ ide that exists to make cross-platform GUI applications.

Visual Studio C++ is also a great tool, but it use dotnet, what it makes Windows Only applications.

Is there another Howto needed to install qtcreator ?

The most common problems to develop C++ applications are this ones :

  • QSqlDatabase: QMYSQL driver not loaded but available.
  • Qt Creator needs a compiler set up to build. Configure a compiler in the kit options.

If you search the internet for this erros, you get alot of solutions, but it just don't work for you, or the explanations are too complicated.

In fact, this errors can be solved in an very easy way.

MySQL

First of all, if you want to use MySQL, download and install an MySQL Server. Good easy setup choices are :

Wampserver

Xampp

Less friendly setup: Mysql Server

After installing the software of your choice, remember where you install the files, because we will need them.

Qtcreator

1. You don't have installed qtcreator yet.

Goto qtcreator website and download the online installer.

2. You already installed qtcreator.

Goto to your QT install folder (standard location = C:\QT) and there you will find the MaintenanceTool.exe.

Installing qtcreator

Run the online installer, or run the MaintenaceTool.exe and choose Add or remove components

If you run the online installer, you can skip the 1st window.

That brings us to the following window

figuur1
Fig 1

Depending on which version of QT you install, the image can differs from yours. Here you see the installation of QT 5.7.

It's important to choose only the components as shown below for QT section:

figuur1
Fig 2

Then for the qtcreator section

figuur1
Fig 3

That's it, after selecting the components, just continue the installation and if you want to use MySQL, don't start it.

Installing MySQL component

Now, goto to your installed Mysql folder inside de lib folder and copy libmysql.dll.

Now, go to your QT folder for example : C:\Qt\5.7\mingw53_32\bin\ and paste the libmysql.dll inside that folder.

Start qt creator now, choose New Project -> QT Console Application -> give it a name. In the next window you should only have 1 kit, Desktop QT version MinGW 32 bits, select Kit -> finish.

Now you should have something like that :

figuur4
Fig 4

There you see a file with the .pro extension. Open that file and add QT += sql

figuur 5
Fig 5

Now open the file main.cpp and apply the changes listed below

#include <QCoreApplication> #include "QSql" #include "QDebug" #include "QSqlDatabase" #include "QSqlError" #include "QString" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL"); db.setHostName("localhost"); db.setDatabaseName("mysql"); db.setPassword("Your_Root_Password"); db.setPort(3306); db.setUserName("root"); bool ok = db.open(); if(ok) { qDebug() << "Database opened !"; db.close(); } else { qDebug() << db.lastError().text(); } return a.exec(); }
figuur 6
Fig 6

Build and run the application. The result :

figuure 7
Fig 7

That's it. As simple as that :)

Leave me a message if you liked it : message