Programming」カテゴリーアーカイブ

プログラミング全般に関するカテゴリーです。

Qtの使い方メモ

Qtの使い方メモ

C++11を使う方法

.proに下記を追加

CONFIG += c++11

QMAKE_CXXFLAGS += -std=c++11なども使えます。

実行ファイルのファイルパスを取得

QCoreApplication::applicationFilePath()

ファイル名だけが欲しい場合はQFileInfoを使って

QFileInfo(QCoreApplication::applicationFilePath()).fileName() 

とできます。

実行ファイルのあるディレクトリを取得

QCoreApplication::applicationDirPath()

アプリケーション名やバージョンを取得

アプリケーション名

QCoreApplication::applicationName()

バージョン番号

QCoreApplication::applicationVersion()

必要なライブラリ(DLL)のコピー

windeployqt.exeというツールで必要なファイル一式をコピーできます。

windeployqt.exe app.exe

app.exeのところは作ったQt製アプリへのパスにします。

windeployqt.exeはQtのインストールで下記の場所にコピーされます。

C:\Qt\<バージョン>\<コンパイラ>\bin

Pythonでカレンダーを表示する

Pythonではcalendarというモジュールを使うと簡単にカレンダーを表示できます。

使い方

>>> import calendar
>>> text = calendar.TextCalendar()
>>> text.formatmonth(2015,1)
    January 2015
Mo Tu We Th Fr Sa Su
          1  2  3  4
 5  6  7  8  9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

日曜日を週の先頭に移動する場合はsetfirstweekdayを使います。

>>> text.setfirstweekday(calendar.SUNDAY)
>>> text.formatmonth(2015,1)
    January 2015
Su Mo Tu We Th Fr Sa
             1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

年間のカレンダー表示はformatyearです。

>>> text.formatyear(2015)

テキストの代わりにHTMLで出力したい場合はHTMLCalendarが使えます。

>>> html = calendar.HTMLCalendar()
>>> html.formatmonth(2015,1)

リンク

8.2. calendar — General calendar-related functions — Python 3.4.3 documentation
https://docs.python.org/3/library/calendar.html