Code less. Create more. Deploy everywhere.
Qt motto, Qt Company
Poem: Qt's a cutie
A framework made to bring you smiles Without a lot to bear; Code less, no stress; make more — galore; And deploy everywhere!
The Qt C++ framework (with Qt officially pronounced as "cute") is software I hold dear to my heart. I have used it since I started learning C++ back in 2010. In fact, I would say Qt was the reason I learned C++.
At the time, I already knew the C programming language but I was looking for a programming language slightly higher level than C to build desktop user interfaces for the code I wrote. I was working with mostly microcontrollers and embedded systems then.
I searched for the best desktop UI framework on Google and Qt popped up on Stack Overflow. Qt was among the favorites being used to make applications like Autodesk Maya, Blender, VirtualBox and Wireshark, so I chose Qt; it just happened to be written with C++.
In this post, I would like to discuss some of the benefits of using Qt.
It's cross-platform
Qt can be used to build applications that run natively on Windows, Mac, and Linux, and in recent years have extended their reach to Android, iOS, Tizen and even the web.
C++ is its core language
C++ gets a lot of hate in programming communities but it is definitely one of my favorite languages (along with Python and JavaScript). I love how close it is to the hardware and how easy it is to connect that knowledge with software.
Qt being written with C++, a fast and efficient language that was similar to C, added to its flair for me.
It has QML
QML, which stands for Qt Modeling Language, has changed the way I think about UI development.
User interfaces can be described with ease in this language. It made me to understand frontend-backend separation more and how that could lead to cleaner code.
It has great documentation
Qt's documentation is so simple and straightforward; I was surprised to see that other documentations are not always the same. I have lost a couple hair follicles from pulling while reading the Android documentation. Qt invests a lot of time in making sure the documentation is easy to understand and apply compared to other UI frameworks.
Easy to use
There is not a lot of required to get started. You could make a button appear on the screen after downloading the Qt SDK with the following code:
#include <QApplication>
#include <QPushButton>
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QPushButton button;
QObject::connect(&button, &QPushButton::clicked, &app, &QApplication::quit);
button.show();
app.exec();
}
Consistency in code
Classes in Qt with similar behavior have consistent interfaces. For instance, both QTcpSocket
and QFile
have a read()
and write()
function, along with the ability to use the stream operators (>>
and <<
) on them. (They both inherit from QIODevice
.) This makes it easy to learn similar classes quickly.
Great API standards
Compared to other UI frameworks, I think Qt's methods are a little more consistent and easy to invoke and memorize. Compare the code for rendering a button in Qt with that of Java Swing and Android:
import javax.swing.*;
public class ButtonExample {
public static void main(String[] args) {
// Create a frame (window)
JFrame frame = new JFrame("Swing Button Example");
frame.setSize(300, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create a button
JButton button = new JButton("Click Me");
// Add action listener to handle clicks
button.addActionListener(e -> {
JOptionPane.showMessageDialog(frame, "Button was clicked!");
});
// Add button to the frame's content pane
frame.getContentPane().add(button);
// Make the frame visible
frame.setVisible(true);
}
}
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button myButton = findViewById(R.id.myButton);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(MainActivity.this, "Button clicked!", Toast.LENGTH_SHORT).show();
}
});
}
}
I know, some complicated stuff 😒.
Multi-language support
Qt supports C++ and Python officially, but work is being done to extend it work with more languages.
Comprehensive framework
Qt also has non-UI modules for database, networking, remote objects etc. This reduces the number of dependencies you need when using it.
It's open source
I had no money when I started programming, so this is important. It was good to use a framework that was completely free to use.
Bottom line
Without Qt, I don't think I would be so immersed in the UI/UX world. Qt carefully crafted their APIs and gave me a reason to care. I appreciate the effort of all the engineers that contributed.
Qt is not perfect. I will definitely circle back later to talk its shortcomings.