New
How do i make a simple QT application without using QT Creator or CMake?
Apr 4, 4:20pm

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:

Step 1: Install Qt

Ensure you have Qt installed on your system. You can download it from the official Qt website.

Step 2: Create Project Structure

Create a directory for your project and navigate into it. Inside this directory, create the following files:

  • main.cpp
  • project.pro

Step 3: Write the Code

main.cpp

This 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.pro

This file is the project file that qmake uses to generate a Makefile. Here's a simple example:

pro
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = simple_qt_app TEMPLATE = app SOURCES += main.cpp

Step 4: Build the Project

  1. Open a terminal and navigate to your project directory.
  2. Run qmake to generate the Makefile:
    bash
    qmake -project qmake
  3. Build the project using make:
    bash
    make

Step 5: Run the Application

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!".

Notes

  • Ensure that the Qt binaries are in your system's PATH so that you can run qmake and make from the command line.
  • This example assumes you are on a Unix-like system. If you are on Windows, you might need to use nmake instead of make.

This setup allows you to create and build a simple Qt application without relying on Qt Creator or CMake.

Apr 4, 4:20pm

This Chat is read-only. Login to resume chatting.

#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(); }
QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = simple_qt_app TEMPLATE = app SOURCES += main.cpp