LoginSignup
2
1

More than 3 years have passed since last update.

DockerでビルドしたQWidgetアプリをMacに表示

Posted at

MacにXサーバをインストール

XQuartz からMacにXサーバをインストールする。

Xサーバを起動してXサーバへのアクセスを許可

インストールしたXQuartzを実行してxtermを起動し、xhostにてXサーバへのアクセスを許可するように変更する。

xhost +

DockerでQtのサンプルアプリをビルド

Qtビルド環境のDockerの作成 で作成したイメージからコンテナを作成する。

docker run -it --name test masana/ubuntu-qtenv:qt5.10.1 /bin/bash

実行に必要なモジュールをインストール

作成したコンテナにおいて、xcbクライアントの実行に必要なモジュールをインストールする。

apt-get install -y libxi6 libxrender1 

ビルドだけでなく実行を前提とするなら、ビルド環境を作成するDockerfileにて上記を追記しておく。

サンプルアプリを実行

作成したコンテナにおいて、ビルドしたサンプルアプリケーションを実行する。

/tmp/sample/sample -display {ホストのMacのIPアドレス}:0.0

MacにQtのウィンドウが表示される。

  • Qtのサンプルプログラム
#include <QApplication>
#include <QLabel>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QLabel label;
    label.setText("TEST");
    label.setAlignment(Qt::AlignCenter);
    label.setGeometry(100,100,500,500);
    label.show();

    return a.exec();
}
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1