Qtを動かしてみる

Qt

Qtとは

いろんなOS(クロスプラットフォーム)で動くGUIツール。
QtはGPLライセンスらしいので,商用はできないみたい。
C++で開発して,アプリケーションを作るために導入

Qtのインストール

以下のURLからダウンロード。

Download Qt: Get Qt Online Installer
Download Qt, an open source development tool containing everything you need for your entire software development life cycle. Install Qt today.

使い方

以下を参考にしました。基本的に同じです。
Macで、Qt5をbrew installしてサクッと起動する。

GUIにボタンを3つ作りたいと思います。
まずは,以下のcppを作成して

qmake -project
を実行。

#include <QtWidgets/QApplication>
#include <QLabel>
#include <QPushButton>
#include <QHBoxLayout>

int main(int argc, char *argv[]) {
    QApplication app(argc, argv);
    QWidget* window = new QWidget;
    QPushButton* buttonA = new QPushButton("Button A");
    QPushButton* buttonB = new QPushButton("Button B");
    QPushButton* buttonC = new QPushButton("Button C");
    QHBoxLayout* layout = new QHBoxLayout;

    layout->addWidget(buttonA);
    layout->addWidget(buttonB);
    layout->addWidget(buttonC);

    window->setLayout(layout);
    window->show(); 

    return app.exec();
}

その後,
qmake hello.pro QT+=widgets
を実行する。するとMakefileが出来上がるので,
make
を実行すると.appができる。

.appをクリックするとGUIが描画される。
t.png

参考

Macで、Qt5をbrew installしてサクッと起動する。
WEBデザイナーの、WEBデザイナーによる、WEBデザイナーの為のサイト、WEB帳は只今、web業界で活躍中のデザイナー、プログラマーによる情報統合サイトです。Javascript、HTML、CSS、Ruby、HTML5,、CSS3、PHP等、フロントエンド技術に特化したブログです。

コメント

タイトルとURLをコピーしました