Minimal Qt Project

Today I was trying to experiment on how small can a Qt project get if I only use the essential modules and scrap away all the rest.

First I created a new Qt project by going to:
File -> New File or Project… -> Application -> Qt Widgets Application

When I build the new project I’m getting this empty window, which is expected:

Then I did the following:

1. Delete mainwindow.ui
2. Delete mainWindow.h and mainWindow.cpp
3. In main.cpp, remove QApplication and replace it with QGuiApplication instead.
4. Use QWindow instead of QMainWindow

The reason why I removed QApplication and QMainWindow is because they both rely on QtWidget module. This way we can reduce the size further by removing one more dependency. Now all I left are just 2 file: Myproject.pro and main.cpp, and they now look like this:

MyProject.pro

TARGET = MyProject
TEMPLATE = app
SOURCES += main.cpp

main.cpp

#include <QGuiApplication>
#include <QWindow>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);
    QWindow window;
    window.setTitle("Hello World!");
    window.resize(640, 480);
    window.show();

    return app.exec();
}

Then I build the project again, which the result should look totally the same as before. However, we no longer need QtWidget.dll anymore which reduces the number of DLL files to just 5:

– libgcc_s_dw2-1.dll
– libstdc++-6.dll
– libwinpthread-1.dll
– Qt5Core.dll
– Qt5Gui.dll

The total size of entire executable folder, including all the DLL files mentioned above, is now only 11.3MB. Its still fairly large if compare to other application framework, but considering two things:

1. There are tons of functionalities in QtCore and QtGui alone, including all the helper classes and even OpenGL
2. All the DLL files in the entire Qt SDK is at the staggering size of 1.87GB in total

11.3MB is actually pretty damn impressive!

Leave a Reply

Your email address will not be published. Required fields are marked *