LoginSignup
3

More than 3 years have passed since last update.

Qtビルド環境のDockerの作成

Last updated at Posted at 2020-08-02

Ubuntu18.04にQt5.10.1のビルド環境をインストール後に、サンプルプログラムをビルドする方法。

qtのインストーラのダウンロード

実行時にwgetで取得する方法もあるが、ここではあらかじめダウンロードしておく。
https://download.qt.io/new_archive/qt/5.10/5.10.1/qt-opensource-linux-x64-5.10.1.run

Qtのサイレントインストーラファイルの作成

Slient install Qt run installer on ubuntu server 

https://stackoverflow.com/questions/25105269/silent-install-qt-run-installer-on-ubuntu-server

Windows環境のコンテナ化

https://qiita.com/tetsurom/items/a591b8f3d2dfe144178f

  • qt-installer-nonintaractive.qs

インストールディレクトリを /opt/Qt でインストールするように指定。
Qt5.10.1はQtIFW3.0.3を使用している。QtIFW3.2.1以降は認証が必要なようだが、このバージョンは認証の指定は不要。
認証の指定をする場合は Controller.prototype.CredentialsPageCallback でメールアドレスとパスワードを指定するか、設定フィアルを用意しておく必要あり。

function Controller() {
    installer.autoRejectMessageBoxes();
    installer.setMessageBoxAutomaticAnswer("installationError", QMessageBox.Retry);
    installer.setMessageBoxAutomaticAnswer("installationErrorWithRetry", QMessageBox.Retry);
    installer.setMessageBoxAutomaticAnswer("DownloadError", QMessageBox.Retry);
    installer.setMessageBoxAutomaticAnswer("archiveDownloadError", QMessageBox.Retry);
    installer.installationFinished.connect(function() {
        gui.clickButton(buttons.NextButton);
    })
}

Controller.prototype.WelcomePageCallback = function() {
    // click delay here because the next button is initially disabled for ~1 second
    gui.clickButton(buttons.NextButton, 3000);
}

Controller.prototype.CredentialsPageCallback = function() {
    gui.clickButton(buttons.NextButton);
}

Controller.prototype.IntroductionPageCallback = function() {
    gui.clickButton(buttons.NextButton);
}

Controller.prototype.TargetDirectoryPageCallback = function()
{
    gui.currentPageWidget().TargetDirectoryLineEdit.setText("/opt/Qt");
    gui.clickButton(buttons.NextButton);
}

Controller.prototype.PerformInstallationPageCallback = function() {
    gui.clickButton(buttons.CommitButton);
}

Controller.prototype.ComponentSelectionPageCallback = function() {
    function list_packages() {
      var components = installer.components();
      console.log("Available components: " + components.length);
      var packages = ["Packages: "];
      for (var i = 0 ; i < components.length ;i++) {
          packages.push(components[i].name);
      }
      console.log(packages.join(" "));
    }

    list_packages();

    var widget = gui.currentPageWidget();
    widget.deselectAll();
    widget.selectComponent("qt.qt5.5101.gcc_64");

    gui.clickButton(buttons.NextButton);
}

Controller.prototype.LicenseAgreementPageCallback = function() {
    gui.currentPageWidget().AcceptLicenseRadioButton.setChecked(true);
    gui.clickButton(buttons.NextButton);
}

Controller.prototype.StartMenuDirectoryPageCallback = function() {
    gui.clickButton(buttons.NextButton);
}

Controller.prototype.ReadyForInstallationPageCallback = function()
{
    gui.clickButton(buttons.NextButton);
}

Controller.prototype.FinishedPageCallback = function() {
    var checkBoxForm = gui.currentPageWidget().LaunchQtCreatorCheckBoxForm;
    if (checkBoxForm && checkBoxForm.launchQtCreatorCheckBox) {
        checkBoxForm.launchQtCreatorCheckBox.checked = false;
    }
    gui.clickButton(buttons.FinishButton);
}

Dockerファイルの作成

  • 最初にapt-getで必要なライブラリをインストール。
  • Qtのサイレントインストールの実行
./qt-opensource-linux-x64-5.10.1.run --script qt-noninteractive.qs --platform minimal
  • インストールパスのbinディレクトリをPATHに追加
  • 作成済のsampleのプログラムを/tmpに展開、qmake→makeでサンプルプログラムをビルド

Dockerfile

FROM ubuntu:18.04

RUN apt-get update -y
RUN apt-get install -y libfontconfig libdbus-1-3 libx11-6 libx11-xcb1
RUN apt-get update -y
RUN apt-get install -y build-essential 
RUN apt-get install -y mesa-common-dev libglu1-mesa-dev libglib2.0-0

COPY qt-installer-noninteractive.qs /qt-noninteractive.qs
COPY qt-opensource-linux-x64-5.10.1.run /qt-opensource-linux-x64-5.10.1.run
RUN chmod +x qt-opensource-linux-x64-5.10.1.run

RUN ./qt-opensource-linux-x64-5.10.1.run --script qt-noninteractive.qs --platform minimal 

ENV PATH $PATH:/opt/Qt/5.10.1/gcc_64/bin

ADD sample.tar /tmp
WORKDIR /tmp/sample
RUN qmake
RUN make

ビルド

ディレクトリにDockerfile、qt-installer-noninteractive.qs、qt-opensource-linux-x64-5.10.1.run、sample.tarを配備して以下を実行。

docker build -t masana/ubuntu-qtenv:qt5.10.1 .

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
3