A hello world Android program using QT Creator.

Creating an Android "Hello World" application using Qt Creator involves several steps. Below is a step-by-step guide to help you through the process:

Prerequisites

  1. Install Qt: Make sure you have Qt installed on your system. You can download it from Qt's official website.
  2. Set Up Android SDK and NDK: Install the necessary Android SDK and NDK as required by Qt.
  3. Install Android Studio: Although not mandatory, having Android Studio can be useful for additional development tasks.

Step-by-Step Guide

Step 1: Open Qt Creator

  1. Launch Qt Creator from your applications menu or desktop shortcut.

Step 2: Create a New Project

  1. In the Welcome mode, click on "Create a new project" to start a new project.
  2. Select "Application" under the "Projects" section and then choose "Qt Widgets Application".
  3. Click "Choose" to proceed with creating the project.

Step 3: Configure Your Project

  1. Give your project a name (e.g., HelloWorldAndroid).
  2. Choose the location where you want to save your project.
  3. Select the kits suitable for Android development. Typically, these will include an Android kit and the appropriate Qt version.
  4. Click "Next".

Step 4: Configure the Project Settings

  1. On the next page, configure the main settings:
    • Class Information: Set the base class to QWidget, and optionally add a new header and source file for your main window (e.g., MainWindow.h and MainWindow.cpp).
  2. Click "Finish" to create the project.

Step 5: Modify Main Window Code

  1. Open the mainwindow.h file and include necessary headers:

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QMainWindow>
    #include <QLabel>
    
    QT_BEGIN_NAMESPACE
    namespace Ui { class MainWindow; }
    QT_END_NAMESPACE
    
    class MainWindow : public QMainWindow
    {
        Q_OBJECT
    
    public:
        MainWindow(QWidget *parent = nullptr);
        ~MainWindow();
    
    private:
        Ui::MainWindow *ui;
        QLabel *helloWorldLabel;
    };
    #endif // MAINWINDOW_H
    
  2. Open the mainwindow.cpp file and modify the constructor to display "Hello World":

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        helloWorldLabel = new QLabel("Hello World", this);
        helloWorldLabel->setAlignment(Qt::AlignCenter);
        setCentralWidget(helloWorldLabel);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    

Step 6: Build and Run the Project

  1. Select the Android kit from the "Projects" mode on the left side.
  2. Click on "Build" to compile your project for Android.
  3. Once the build is successful, click on the green "Run" button (or press F5) to deploy the app to an connected Android device or emulator.

Step 7: Test Your Application

  1. Ensure that your Android device is properly connected and debugging is enabled.
  2. The application should install and run on your Android device, displaying a centered "Hello World" message.

Troubleshooting Tips

  • If you encounter issues with the Android SDK or NDK paths, ensure they are correctly set in Qt Creator's preferences under "Tools" > "Options" > "Build & Run" > "Kits".
  • Make sure your Android device has USB debugging enabled and is connected via a USB cable.

That's it! You have successfully created and run an Android "Hello World" application using Qt Creator.