メインコンテンツへスキップ
見出し画像

Qt(C++)+Qwtでグラフウィジェット配置するまで

    Qtでグラフを描こうと思い、QtのサードパーティC++ライブラリであるところのQwtを導入したのですが、その導入まで思いの外時間がかかったのでその備忘録です。

    環境

    ・OS:Windows10
    ・C++デバッグツール:Visual Studio 2019
    ・Qt 6.2.3
    ・Qwt 6.2.0

    Qtのインストール

    Windows環境のQtのインストールは青木健一郎様作成のマニュアルを参考に進めます。
    Visual Studioをインストール済みなので、「4. コンポーネント選択」でMinGWでなく、「MSVC 2019 64-bit」を選択しました。

    コンポーネント一覧

    Qt 6.2.3
    ・MSVC 2019 64-bit:Visual Studioインストール済みのため
    ・Qt Multimedia:音声ファイルを扱いたいため
    ・Qt Debug Information Files:標準

    Developer and Designer Tools
    ・Qt Creator 6.0.2 CDB Debugger Support:標準
    ・Debugging Tools for Windows:デバッグ時必要のため
    ・Qt Design Studio 3.1.0:標準
    ・CMake 3.21.1 64-bit:標準
    ・Ninja 1.10.2:標準

    画像
    Qtの保守画面で確認

    Qt Multimediaは任意ですが、基本的に上記があれば問題ありません。
    あとはマニュアルに沿って進め、インストール完了を待ちます。

    Qwtのインストール

    続いてQwtをインストールします。
    インストール手順は公式のドキュメントに沿います。

    1: Qwtのダウンロード

    Qwt自体のファイルをプロジェクトページからダウンロードします。Windows環境であれば「qwt-6.2.0.zip」を選択します(執筆時最新版)。

    画像
    3個目の「qwt-6.2.0.zip」選択しダウンロード

    2: 解凍

    ダウンロードしたzipファイルを解答し、任意の場所に配置します。自分の場合は「C:\temp\qwt-6.2.0」に配置しました。

    3: makefile作成準備

    「x64 Native Tools Command Prompt for VS 2019」を起動し、コマンド画面のディレクトリを"C:\temp\qwt-6.2.0"に変更します。

    C:\Program Files (x86)\Microsoft Visual Studio\2019\Community>cd C:\temp\qwt-6.2.0

    4: makefile作成

    qmakeコマンドでmakefileを作成します。

    C:\temp\qwt-5.2.3>qmake qwt.pro
    Info: creating stash file C:\temp\qwt-5.2.3\.qmake.stash

    もしエラーが出た場合、環境変数の設定を見直します。"C:\Qt\6.2.3\msvc2019_64\bin"をPathに登録しておきます。
    参考:https://www.scc-kk.co.jp/scc-books/java8_workbook/java_dev-win10.html

    5: nmakeの実行

    nmakeします。

    C:\temp\qwt-6.2.0>nmake
    
    Microsoft(R) Program Maintenance Utility Version 14.29.30141.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            cd src\ && ( if not exist Makefile C:\Qt\6.2.3\msvc2019_64\bin\qmake.exe -o Makefile C:\temp\temp\qwt-6.2.0\src\src.pro ) && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\nmake.exe" -f Makefile
    
    Microsoft(R) Program Maintenance Utility Version 14.29.30141.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\nmake.exe" -f Makefile.Release all
    
    Microsoft(R) Program Maintenance Utility Version 14.29.30141.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    generating moc/moc_predefs.h
    moc qwt_dyngrid_layout.h
    moc qwt_magnifier.h
    moc qwt_panner.h
    moc qwt_picker.h
    moc qwt_text_label.h
    moc qwt_abstract_legend.h
    moc qwt_legend.h
    moc qwt_legend_label.h
    moc qwt_plot.h
    moc qwt_plot_renderer.h
    moc qwt_plot_canvas.h
    moc qwt_plot_panner.h
    moc qwt_plot_picker.h
    moc qwt_plot_zoomer.h
    moc qwt_plot_magnifier.h
    moc qwt_plot_rescaler.h
    moc qwt_sampling_thread.h
    moc qwt_scale_widget.h
    moc qwt_plot_opengl_canvas.h
    moc qwt_polar_canvas.h
    moc qwt_polar_magnifier.h
    moc qwt_polar_panner.h
    moc qwt_polar_picker.h
    moc qwt_polar_plot.h
    moc qwt_polar_renderer.h
    moc qwt_abstract_slider.h
    moc qwt_abstract_scale.h
    moc qwt_analog_clock.h
    moc qwt_compass.h
    moc qwt_counter.h
    moc qwt_dial.h
    moc qwt_knob.h
    moc qwt_slider.h
    moc qwt_thermo.h
    moc qwt_wheel.h
    qwt.cpp
    qwt_abstract_scale_draw.cpp
    qwt_bezier.cpp
    qwt_clipper.cpp
     
    …中略…
     
    Microsoft(R) Program Maintenance Utility Version 14.29.30141.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\nmake.exe" -f Makefile.Release all
    
    Microsoft(R) Program Maintenance Utility Version 14.29.30141.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    Plot.cpp
    main.cpp
    コードを生成中...
    linking ..\bin\animation.exe
    MSVCRT.lib(exe_winmain.obj) : error LNK2019: 未解決の外部シンボル WinMain が関数 "int __cdecl __scrt_common_main_seh(void)" (?__scrt_common_main_seh@@YAHXZ) で参照されました
    ..\bin\animation.exe : fatal error LNK1120: 1 件の未解決の外部参照
    NMAKE : fatal error U1077: 'echo' : リターン コード '0x460'
    Stop.
    NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\nmake.exe"' : リターン コード '0x2'
    Stop.
    NMAKE : fatal error U1077: 'cd' : リターン コード '0x2'
    Stop.
    NMAKE : fatal error U1077: 'cd' : リターン コード '0x2'
    Stop.
    
    C:\temp\temp\qwt-6.2.0>

    自分の環境ではエラーで止まったので、下記の解決策を試したところ、うまくいきました。

    「animation」のリンクに失敗しているので、該当フォルダの「Makefile.Debug」「Makefile.Release」を書き換えます。
    "C:\temp\qwt-6.2.0\examples\animation\Makefile.Debug"
    "C:\temp\qwt-6.2.0\examples\animation\Makefile.Release"

    21行目のLFLAGSの最後に、「/ENTRY:mainCRTStartup」と書き加えます。

    LFLAGS        = /NOLOGO /DYNAMICBASE /NXCOMPAT /DEBUG /SUBSYSTEM:WINDOWS "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" /ENTRY:mainCRTStartup

    そして再度nmakeを実行します。
    すると次は別のフォルダに対し同じエラーが発生するので、再び「Makefile.Debug」「Makefile.Release」を書き換えて……を繰り返します。
    時間がかかります。

    最終的にすべてのエラーが解消されると次の出力が得られます。

    ...中略...
    
    Microsoft(R) Program Maintenance Utility Version 14.29.30141.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            cd splineprof\ && ( if not exist Makefile C:\Qt\6.2.3\msvc2019_64\bin\qmake.exe -o Makefile C:\temp\qwt-6.2.0\tests\splineprof\splineprof.pro ) && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\nmake.exe" -f Makefile
    
    Microsoft(R) Program Maintenance Utility Version 14.29.30141.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\nmake.exe" -f Makefile.Release all
    
    Microsoft(R) Program Maintenance Utility Version 14.29.30141.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    linking ..\bin\splineprof.exe
            "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\nmake.exe" -f Makefile.Debug all
    
    Microsoft(R) Program Maintenance Utility Version 14.29.30141.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
    main.cpp
    linking ..\bin_debug\splineprof.exe

    6: 最後にインストールを行います。

    C:\temp\qwt-6.2.0>nmake install
    
    Microsoft(R) Program Maintenance Utility Version 14.29.30141.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            cd src\ && ( if not exist Makefile C:\Qt\6.2.3\msvc2019_64\bin\qmake.exe -o Makefile C:\temp\qwt-6.2.0\src\src.pro ) && "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\nmake.exe" -f Makefile install
     
    ...中略...
    
            "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\HostX64\x64\nmake.exe" -f Makefile.Debug install
    
    Microsoft(R) Program Maintenance Utility Version 14.29.30141.0
    Copyright (C) Microsoft Corporation.  All rights reserved.
    
            C:\Qt\6.2.3\msvc2019_64\bin\qmake.exe -install qinstall C:\temp\qwt-6.2.0\qwtconfig.pri C:\Qwt-6.2.0\features\qwtconfig.pri
            C:\Qt\6.2.3\msvc2019_64\bin\qmake.exe -install qinstall C:\temp\qwt-6.2.0\qwtfunctions.pri C:\Qwt-6.2.0\features\qwtfunctions.pri
            C:\Qt\6.2.3\msvc2019_64\bin\qmake.exe -install qinstall C:\temp\qwt-6.2.0\qwt.prf C:\Qwt-6.2.0\features\qwt.prf
    
    C:\temp\qwt-6.2.0>
    

    以上でインストールは完了です。"C:\Qwt-6.2.0"が生成されます。

    画像
    "C:\Qwt-6.2.0"


    Qt Creatorへの反映とウィジェット配置

    インストールしたdllファイル
    "C:\Qwt-6.2.0\plugins\designer\qwt_designer_plugin.dll"
    をQt Creatorへ反映させます。

    上記ファイルを
    "C:\Qt\Tools\QtCreator\bin\plugins\designer\qwt_designer_plugin.dll"
    となるようにコピーします。

    作業自体は以上で完了ですが、dllファイルが読み込めたことを確認しておきます。

    Qt Creatorで適当なプロジェクトを作成し、[ツール]->[フォームエディタ]->[Qt Designer プラグインについて]を選択し「qwt_designer_plugin.dll」が読み込まれていることを確認します。

    画像
    Qt Designer プラグインについて

    GUI上もQwt Widgetという名前でウィジェット配置ができるようになります。

    画像
    グラフ以外に目盛りや時計のウィジェット配置が可能に


     
     

    歌津

     
     
    noteはじめました。少しずつ更新します。

    あなたへのおすすめ