Back to PortfolioSynced from GitHub

LocalChatAppQT

Complete README documentation

LocalChatApp

A Qt-based local chat application demonstrating inter-window communication using Qt's signal-slot system.
Radar Panel

Project Overview

LocalChatApp is a desktop application built with Qt6 that implements a two-window chat system. The application demonstrates real-time bidirectional communication between two independent windows using Qt's signal-slot mechanism.

Features

  • Dual Window Interface: Main window and separate chat window
  • Real-time Messaging: Bidirectional message synchronization between windows
  • User Identification: Different user types ("Main User" and "Chat User")
  • Timestamp Display: All messages include timestamp formatting
  • Typing Indicators: Real-time typing status updates
  • Independent Windows: Chat window can be moved freely from main window
  • Status Updates: Status bar notifications for user actions

Technology Stack

  • Framework: Qt 6.9.1
  • Language: C++17
  • Build System: CMake 3.16+
  • UI Design: Qt Designer (.ui files)
  • Development Environment: MinGW 64-bit

Architecture

Core Components

  • MainWindow (mainwindow.h/cpp): Primary application window

    • Contains chat log display
    • Message input for "Main User"
    • "Open Chat Window" button
    • Status bar for notifications
  • ChatWindow (chatwindow.h/cpp): Secondary chat window

    • Independent chat interface
    • Message input for "Chat User"
    • Real-time message display

Communication Protocol

The application uses Qt's signal-slot system for inter-window communication:

// Signal declarations
signals:
    void messageReceived(const QString &message);  // ChatWindow → MainWindow
    void messageSent(const QString &message);      // MainWindow → ChatWindow
    void chatClosed();                             // ChatWindow → MainWindow
    void userTyping(const QString &username);      // Typing notifications

Key Signal-Slot Connections

// Inter-window message passing
connect(chatWindow, &ChatWindow::messageReceived, this, &MainWindow::onMessageReceived);
connect(this, &MainWindow::messageSent, chatWindow, &ChatWindow::receiveMessage);

// Window lifecycle management
connect(chatWindow, &ChatWindow::chatClosed, this, &MainWindow::onChatClosed);

// Typing indicators
connect(chatWindow, &ChatWindow::userTyping, this, &MainWindow::onUserTyping);

Project Structure

LocalChatApp/
├── CMakeLists.txt              # Build configuration
├── main.cpp                    # Application entry point
├── mainwindow.h/cpp           # Main window implementation
├── mainwindow.ui              # Main window UI layout
├── chatwindow.h/cpp           # Chat window implementation
├── chatwindow.ui              # Chat window UI layout
├── Qt_Tutorial_Step_by_Step.txt # Detailed tutorial
├── src/
│   └── img.png                # Image resource
└── build/                     # Build artifacts

Building the Project

Prerequisites

  • Qt 6.1 or higher
  • CMake 3.16 or higher
  • C++17 compatible compiler (MinGW, MSVC, or GCC)

Build Steps

  1. Clone or extract the project
cd LocalChatApp
  1. Create build directory
mkdir build
   cd build
  1. Configure with CMake
cmake ..
  1. Build the application
cmake --build .
  1. Run the executable
./LocalChatApp

Usage

  1. Launch the application: Run the executable to open the main window
  2. Open chat window: Click "Open Chat Window" button
  3. Start chatting:
    • Type messages in either window
    • Messages appear in both windows with timestamps
    • User identification shows "Main User" vs "Chat User"
  4. Monitor status: Watch status bar for typing indicators and notifications

Key Qt Concepts Demonstrated

Signal-Slot System

  • Custom signal definitions
  • Cross-object communication
  • Real-time event handling

Window Management

  • Independent window positioning
  • Parent-child relationships (nullptr for independence)
  • Proper window lifecycle management

UI Design

  • Qt Designer integration
  • Dynamic UI updates
  • Responsive layouts

Memory Management

  • Automatic parent-child cleanup
  • Proper object deletion with deleteLater()

Message Flow

User Input → Signal Emission → Slot Execution → UI Update

Example:
1. User types in ChatWindow
2. textChanged() signal emitted
3. onTextChanged() slot called
4. "Typing..." status sent to MainWindow
5. MainWindow status bar updated

Development Notes

  • The application uses Qt's automatic UI compilation (AUTOUIC, AUTOMOC, AUTORCC)
  • UI files are designed with Qt Designer for visual layout
  • Signal-slot connections are established programmatically for maximum control
  • Independent window architecture allows flexible window management

Educational Value

This project serves as a comprehensive tutorial for:

  • Qt application development fundamentals
  • Signal-slot communication patterns
  • Multi-window application architecture
  • Real-time UI synchronization
  • Cross-platform GUI development

Future Enhancement Possibilities

  • Network communication between different application instances
  • Chat history persistence
  • Multiple chat rooms
  • User authentication
  • File sharing capabilities
  • Custom themes and styling

License

Educational project - refer to Qt licensing for commercial use considerations.