Qt Tutorials For Beginners – First Qt GUI widget Application




Qt Tutorials For Beginners
Qt Tutorials For Beginners

In this tutorial we will see How to create First Qt GUI widget Application.

File->New File or Project…

Applications->Qt Gui Application->Choose…

We keep the class as MainWindow as given by default.

Qt Project Structure
Qt Project Structure

 

GUI Design

Qt Project Structure - Gui Design
Qt Project Structure – Gui Design

 

FirstGUI.pro
#-------------------------------------------------
#
# Project created by QtCreator 2016-04-12T23:11:13
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = FirstGUI
TEMPLATE = app


SOURCES += main.cpp\
        mainwindow.cpp

HEADERS  += mainwindow.h

FORMS    += mainwindow.ui

 

mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

private slots:
    void on_pushButtonClose_clicked();

private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

 

mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButtonClose_clicked()
{
    ui->label->setText("Button is clicked");
}

 

main.cpp

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();

    return a.exec();
}

Output:

First Qt GUI Output
First Qt GUI Output

Partner Sites

VideoToGifs.com

EasyOnlineConverter.com

SqliteTutorials.com





Be the first to comment

Leave a Reply

Your email address will not be published.


*