Creating a simple Qt application without using Qt Creator or CMake involves writing the necessary code and configuration files manually. Here's a step-by-step guide to create a basic Qt application using just a text editor and the command line:
Ensure you have Qt installed on your system. You can download it from the official Qt website.
Create a directory for your project and navigate into it. Inside this directory, create the following files:
main.cppproject.promain.cppThis file will contain the main application code. Here's a simple example of a Qt application that displays a window with a button:
cpp#include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton button("Hello, World!"); button.resize(200, 100); button.show(); return app.exec(); }
project.proThis file is the project file that qmake uses to generate a Makefile. Here's a simple example:
proQT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = simple_qt_app TEMPLATE = app SOURCES += main.cpp
qmake to generate the Makefile:
bashqmake -project qmake
make:
bashmake
After building the project, you can run the application using:
bash./simple_qt_app
This will launch a simple Qt application with a window containing a button that says "Hello, World!".
qmake and make from the command line.nmake instead of make.This setup allows you to create and build a simple Qt application without relying on Qt Creator or CMake.