「Qtの設定 - コマンドライン引数」の版間の差分

📢 Webサイト閉鎖と移転のお知らせ
このWebサイトは2026年9月に閉鎖いたします。
新しい記事は移転先で追加しております。(旧サイトでは記事を追加しておりません)

文字列「__FORCETOC__」を「{{#seo: |title={{PAGENAME}} : Exploring Electronics and SUSE Linux | MochiuWiki |keywords=MochiuWiki,Mochiu,Wiki,Mochiu Wiki,Electric Circuit,Electric,pcb,Mathematics,AVR,TI,STMicro,AVR,ATmega,MSP430,STM,Arduino,Xilinx,FPGA,Verilog,HDL,PinePhone,Pine Phone,Raspberry,Raspberry Pi,C,C++,C#,Qt,Qml,MFC,Shell,Bash,Zsh,Fish,SUSE,SLE,Suse Enterprise,Suse Linux,openSUSE,open SUSE,Leap,Linux,uCLnux,Podman,電気回路,電子回路,基板,プリント基板 |description={{PAGENAME}} - 電子回路とSUSE Linuxに関する情報 | This pag…
 
(同じ利用者による、間の2版が非表示)
8行目: 8行目:


== QCommandLineParserクラスの使用 ==
== QCommandLineParserクラスの使用 ==
以下の例では、<code>QCommandLineParser</code>クラスを使用して、指定されたオプションを処理している。<br>
以下の例では、<code>QCommandLineParser</code>クラスを継承したサブクラスを定義して、指定されたオプションを処理している。<br>
<br>
<br>
* QCommandLineParserクラスを使用してコマンドラインオプションを定義する。
<code>QCommandLineParser</code>クラスのデフォルトの動作により、例えば、--hオプションが-hオプションと同様に処理されてしまう。<br>
* -hオプション、--helpオプション、-vオプション、--versionオプションは、その後に続く値が不要なため、Qtにより自動的に処理される。
この問題を解決するために、<code>QCommandLineParser</code>クラスの<code>process</code>メソッドをオーバーライドして、カスタムの解析ロジックを実装している。<br>
* -cオプション、--configオプションを追加で定義して、値を受け取るように指定する。
<br>
* 上記に存在しないオプションが指定された場合、それらを表示する。
正規表現を使用して、有効なオプション (-v, -h, -c, --version, --help, --config) のみを受け付けるようにする。<br>
上記に存在しないオプションが指定された場合は、"不明なオプション"として処理する。<br>
<br>
<br>
  <syntaxhighlight lang="c++">
  <syntaxhighlight lang="c++">
112行目: 113行目:
<br>
<br>
<u>※注意</u><br>
<u>※注意</u><br>
<code>QCommandLineParser</code>クラスは、様々なケースに対応できるような構造になっている。<br>
<u><code>QCommandLineParser</code>クラスは、様々なケースに対応できるような構造になっている。</u><br>
詳細は、<code>[https://doc.qt.io/qt-5/qcommandlineparser.html QCommandLineParser]</code>と<code>[https://doc.qt.io/qt-5/qcommandlineoption.html QCommandLineOption]</code>のドキュメントを参照すること。<br>
<br>
また、他の使用方法については、[https://code.qt.io/cgit/qt/qtbase.git/tree/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp qtbase/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp]のテストケースを参照すること。<br>
<u><code>QCommandLineParser</code>クラスの詳細は、Qt公式ドキュメントを参照すること。</u><br>
* QCommandLineParserクラス
*: Qt 6 : https://doc.qt.io/qt-6/qcommandlineparser.html
*: Qt 5 : https://doc.qt.io/qt-5/qcommandlineparser.html
* QCommandLineOptionクラス
*: https://doc.qt.io/qt-6/qcommandlineoption.html
*: https://doc.qt.io/qt-5/qcommandlineoption.html
<br>
また、他の使用方法については、<code>QCommandLineParser</code>クラスのテストケースを参照すること。<br>
* https://code.qt.io/cgit/qt/qtbase.git/tree/tests/auto/corelib/tools/qcommandlineparser/tst_qcommandlineparser.cpp
<br><br>
<br><br>


172行目: 182行目:
  "hoge \" piyo" fuga
  "hoge \" piyo" fuga
<br><br>
<br><br>
{{#seo:
|title={{PAGENAME}} : Exploring Electronics and SUSE Linux | MochiuWiki
|keywords=MochiuWiki,Mochiu,Wiki,Mochiu Wiki,Electric Circuit,Electric,pcb,Mathematics,AVR,TI,STMicro,AVR,ATmega,MSP430,STM,Arduino,Xilinx,FPGA,Verilog,HDL,PinePhone,Pine Phone,Raspberry,Raspberry Pi,C,C++,C#,Qt,Qml,MFC,Shell,Bash,Zsh,Fish,SUSE,SLE,Suse Enterprise,Suse Linux,openSUSE,open SUSE,Leap,Linux,uCLnux,Podman,電気回路,電子回路,基板,プリント基板
|description={{PAGENAME}} - 電子回路とSUSE Linuxに関する情報 | This page is {{PAGENAME}} in our wiki about electronic circuits and SUSE Linux
|image=/resources/assets/MochiuLogo_Single_Blue.png
}}


__FORCETOC__
__FORCETOC__
[[カテゴリ:Qt]]
[[カテゴリ:Qt]]