Develop Qt GUI Widgets without Using QtCreator

Chuan Zhang
2 min readAug 13, 2020

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)));
}
model.setItem(i,j,item);
}
}
}
tree->setModel(&model);
tree->show();
return a.exec();
}

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

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

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

chuan@axon:~/…/Examples00$ qmake Examples00.pro -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.

Screenshot of the QTreeView widget created with the C++ code in above example

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.

--

--