Develop Qt GUI Widgets without Using QtCreator

Jan. 18. 2016

QtCreator is a very convenient IDE for developing Qt GUI programs. Under Ubuntu Linux 14.04, this note demonstrates an alternative way to develop Qt GUI programs without using QtCreator in an example.

First, use any text editor, say gedit, nodepad++, etc, to edit your source code. Here for simplicity, we write everything in a single .cpp file as follows.

// main.cpp
#include <QApplication>
#include <QTreeView>
#include <QStandardItemModel>
using namespace std;int main(int argc, char* argv[])
QApplication a(argc, argv);
QTreeView *tree = new QTreeView;
QStandardItemModel model(3, 3);
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++)
QStandardItem *item = new QStandardItem(QString(“Row:%1, Column:%2”).arg(i).arg(j));
if (j == 0)
for (int k = 0; k < 3; k++)
item->appendRow(new QStandardItem(QString(“Item %1”).arg(i)));
return a.exec();

Next, create a .pro file with any text editor as follows.

Qt += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Examples00
# Input
SOURCES += main.cpp

Then use the following qmake command in command line terminal to generate Makefile file.

chuan@axon:~/…/Examples00$ qmake -r -spec linux-g++ CONFIG+=debug

Last use make command to compile the source code to produce the executable binary code. The figure below shows the QTreeView widget created by the program.

By the way, you can definitely and very easily use QtCreator but not Designer to develop GUI programs. What you need to is just create an empty Qt Project, then adding the code as what we have demonstrated above. For Qt Creator 3.5.0(opensource), you can find the option at: File > New File or Project; then in the Projects column of New File or Project dialog, find Other Project; then Choose Empty qmake Project, then following the instruction to finish setting the project.

In my BuildSystems repository, I included one example project, which is a little more elaborated than the one I demonstrated here. That project used not only widgets from Qt, but also the signal-slot communication mechanism. Therefore, it has to use moc (meta-object compiler), which is very different from the example I used in this post. If you are interested, feel free to check my example project built with the GNU Make build system here.

Senior Software/Data Engineer