Введение в кроссплатформенное - My

П. В. Матренин
Введение в
кроссплатформенное
программирование на С++ в
Qt
Методические указания
Москва
Издательство Нобель Пресс
УДК 62-63
ББК 30.6
П11
П11
П. В. Матренин
Введение в кроссплатформенное программирование на С++ в Qt: Методические указания / П. В. Матренин – М.: Lennex Corp, — Подготовка макета:
Издательство Нобель Пресс, 2013. – 55 с.
ISBN 978-5-518-40395-6
Рассмотренные в методическом пособии теоретические положения
и учебные примеры позволяют студентам быстро освоить технологию создания программных продуктов в среде Qt 4 на языке С++. Qt является кроссплатформенным инструментом разработки программного обеспечения любой
сложности, которое будет работать во всех основных операционных системах
(Windows, Mac OS X, Unix, Linux, системы для мобильных устройств
и встраиваемые системы) без изменения исходного кода. Qt используется
в AMD, Disney, Google, HP, KDE, Oracle, Siemens, Skype, Sumsung и др.
В пособии рассмотрены особенности Qt, дан обзор IDE Qt Creator и приведены два учебных примера, в которых подробно, по шагам описан процесс создания приложений с графическим интерфейсом пользователя, механизм
сигналов и слотов, работа с текстовыми файлами, создание интерфейсов
в визуальном дизайнере и процесс интернационализации приложений. Приведены исходные коды с комментариями и пояснениями.
ISBN 978-5-518-40395-6
© Издательство Нобель Пресс, 2013
© П. В. Матренин, 2013
Ɉɝɥɚɜɥɟɧɢɟ
Ɉɛɳɢɟɩɨɥɨɠɟɧɢɹ«««««««««««««««««5
ɐɟɥɶɥɚɛɨɪɚɬɨɪɧɵɯɪɚɛɨɬ................................................ 5
Ɍɟɦɵɥɚɛɨɪɚɬɨɪɧɵɯɪɚɛɨɬ............................................... 5
ɋɢɫɬɟɦɚɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹQt ....................................... 6
Ɉɛɡɨɪɫɪɟɞɵɪɚɡɪɚɛɨɬɤɢ««««««««««««««7
Ɂɧɚɤɨɦɫɬɜɨɫ4Wɫɢɝɧɚɥɵɢɫɥɨɬɵ.................................. 7
ɁɚɩɭɫɤɫɢɫɬɟɦɵQt Creator............................................. 10
Ʉɪɚɬɤɢɣɨɛɡɨɪ4W&UHDWRU ............................................... 11
ɉɚɧɟɥɢɜɵɜɨɞɚ ......................................................... 12
ɍɩɪɚɜɥɟɧɢɟɫɟɫɫɢɹɦɢɜ4W&UHDWRU ......................... 13
ɂɧɬɟɝɪɚɰɢɹɫɩɪɚɜɤɢɩɨ4W ..................................... 13
ɂɧɬɟɝɪɚɰɢɹɫ4W'HVLJQHU ....................................... 14
Ɍɟɤɫɬɨɜɵɣɪɟɞɚɤɬɨɪ................................................... 15
ɋɨɡɞɚɧɢɟɩɪɨɟɤɬɚɜ4W&UHDWRU ...................................... 19
ɋɨɡɞɚɧɢɟɧɨɜɨɝɨɩɪɨɟɤɬɚ ....................................... 19
ɍɫɬɚɧɨɜɤɚɢɦɟɧɢɩɪɨɟɤɬɚɢɟɝɨɪɚɡɦɟɳɟɧɢɹ ....... 20
ɍɤɚɡɚɧɢɟɢɧɮɨɪɦɚɰɢɢɨɤɥɚɫɫɟ ............................. 20
Ɉɬɥɚɞɤɚɫɩɨɦɨɳɶɸ4W&UHDWRU ..................................... 21
ȼɜɟɞɟɧɢɟ .................................................................. 21
ȼɡɚɢɦɨɞɟɣɫɬɜɢɟɫɨɬɥɚɞɱɢɤɨɦ .............................. 21
Ɍɨɱɤɢɨɫɬɚɧɨɜɚ........................................................ 21
ȼɵɩɨɥɧɟɧɢɟ ............................................................. 22
ɋɬɟɤ .......................................................................... 23
ɉɟɪɟɦɟɧɧɵɟɢɜɵɪɚɠɟɧɢɹ ...................................... 23
ȾɢɡɚɫɫɟɦɛɥɟɪɢɊɟɝɢɫɬɪɵ ...................................... 25
ɉɨɬɨɤɢ...................................................................... 25
ɇɚɫɬɪɨɣɤɢɫɪɟɞɵ ............................................................ 25
Ʌɚɛɨɪɚɬɨɪɧɚɹɪɚɛɨɬɚʋ«««««««««««««26
Ɉɫɧɨɜɵɧɚɩɪɢɦɟɪɟɫɨɡɞɚɧɢɹɬɟɤɫɬɨɜɨɝɨɪɟɞɚɤɬɨɪɚ .. 26
ɇɚɱɚɥɨɪɚɡɪɚɛɨɬɤɢɧɨɜɨɝɨɩɪɢɥɨɠɟɧɢɹ ............... 26
ɉɪɨɟɤɬɧɵɟɮɚɣɥɵpro ............................................ 28
Ɉɩɢɫɚɧɢɟɤɥɚɫɫɚɝɥɚɜɧɨɝɨɨɤɧɚ ............................. 29
Ʉɨɧɫɬɪɭɤɬɨɪɝɥɚɜɧɨɝɨɨɤɧɚ ................................... 31
Ɉɛɪɚɛɨɬɤɚɫɨɛɵɬɢɣ................................................. 31
Ɋɟɚɥɢɡɚɰɢɹɫɥɨɬɨɜ................................................... 32
ɂɤɨɧɤɚɢɪɟɫɭɪɫɵ ................................................... 33
3
Ⱦɟɣɫɬɜɢɹ .................................................................. 35
ɋɨɡɞɚɧɢɟɦɟɧɸ ........................................................ 37
ɋɨɡɞɚɧɢɟɩɚɧɟɥɢɢɧɫɬɪɭɦɟɧɬɨɜ .......................... 37
ɋɬɪɨɤɚɫɨɫɬɨɹɧɢɹ .................................................. 38
3.1.12ɋɨɯɪɚɧɟɧɢɟɧɚɫɬɪɨɟɤɩɪɢɥɨɠɟɧɢɹ ...................... 38
Ɏɭɧɤɰɢɢɞɥɹɪɚɛɨɬɵɫɮɚɣɥɚɦɢ .......................... 39
Ɂɚɩɭɫɤɩɪɢɥɨɠɟɧɢɹ ............................................... 41
Ⱦɨɩɨɥɧɢɬɟɥɶɧɵɟɜɨɡɦɨɠɧɨɫɬɢ ..................................... 44
Ⱦɨɛɚɜɥɟɧɢɟ ɨɛɴɟɤɬɨɜ ɧɚ ɮɨɪɦɭ ɢɡɦɟɧɟɧɢɟ ɢɯ
ɫɜɨɣɫɬɜ .................................................................................... 44
Ʉɨɦɩɨɧɨɜɤɚɨɛɴɟɤɬɨɜ ............................................. 45
ɉɨɪɹɞɨɤɨɛɯɨɞɚɷɥɟɦɟɧɬɨɜ .................................... 47
ɋɢɝɧɚɥɵɢɫɥɨɬɵɉɪɟɞɩɪɨɫɦɨɬɪ .......................... 48
ɋɜɹɡɶɤɥɚɫɫɚɝɥɚɜɧɨɝɨɨɤɧɚɢɟɝɨɮɨɪɦɵ ............. 50
ɂɧɬɟɪɧɚɰɢɨɧɚɥɢɡɚɰɢɹɩɪɢɥɨɠɟɧɢɹ ...................... 51
Ɂɚɤɥɸɱɟɧɢɟ«««««««««««««««««««54
ɋɩɢɫɨɤɥɢɬɟɪɚɬɭɪɵ«««««««««««««««««55
ɉɊɂɅɈɀȿɇɂȿ««««««««««««««««««56
4
1. Ɉɛɳɢɟɩɨɥɨɠɟɧɢɹ
ɐɟɥɶɥɚɛɨɪɚɬɨɪɧɵɯɪɚɛɨɬ
ɂɡɭɱɟɧɢɟ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɨɣ ɫɢɫɬɟɦɵ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ 4W
(Qt SDK, Qt Creator) ɢ ɪɚɡɪɚɛɨɬɤɚ ɧɚ ɟɟ ɨɫɧɨɜɟ ɭɱɟɛɧɵɯ ɢ
ɞɟɦɨɧɫɬɪɚɰɢɨɧɧɵɯ ɩɪɢɥɨɠɟɧɢɣ ɫ ɝɪɚɮɢɱɟɫɤɢɦ ɢɧɬɟɪɮɟɣɫɨɦ
ɩɨɥɶɡɨɜɚɬɟɥɹ ɩɨɫɜɹɳɟɧɧɵɯ ɢɡɭɱɟɧɢɸ ɤɥɸɱɟɜɵɯ ɜɨɩɪɨɫɨɜ
ɬɟɯɧɨɥɨɝɢɢ
ɨɛɴɟɤɬɧɨ-ɨɪɢɟɧɬɢɪɨɜɚɧɧɨɝɨ
ɚɧɚɥɢɡɚ
ɩɪɨɟɤɬɢɪɨɜɚɧɢɹɢɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ
Ɍɟɦɵɥɚɛɨɪɚɬɨɪɧɵɯɪɚɛɨɬ
ɂɡɭɱɟɧɢɟ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɨɣ ɫɢɫɬɟɦɵ ɨɛɴɟɤɬɧɨɨɪɢɟɧɬɢɪɨɜɚɧɧɨɝɨ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ 4W Qt
4.x
ɫ
ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ ɪɟɞɚɤɬɨɪɚ QtCreator 2.x ɢ ɟɟ ɩɪɢɦɟɧɟɧɢɟ ɞɥɹ
ɜɢɡɭɚɥɶɧɨɣ ɪɚɡɪɚɛɨɬɤɢ ɩɪɢɥɨɠɟɧɢɹ ɫ ɞɪɭɠɟɫɬɜɟɧɧɵɦ
ɝɪɚɮɢɱɟɫɤɢɦɢɧɬɟɪɮɟɣɫɨɦɩɨɥɶɡɨɜɚɬɟɥɹ
Ɋɚɡɪɚɛɨɬɤɚ ɤɥɚɫɫɚ ɩɪɟɞɫɬɚɜɥɹɸɳɟɝɨ ɡɚɞɚɧɧɭɸ
ɩɪɟɞɦɟɬɧɭɸ ɨɛɥɚɫɬɶ ɢ ɢɧɬɟɪɚɤɬɢɜɧɨɝɨ ɩɪɢɥɨɠɟɧɢɹ
ɞɟɦɨɧɫɬɪɢɪɭɸɳɟɝɨɪɚɛɨɬɭɦɟɬɨɞɨɜɤɥɚɫɫɚ
Ɋɚɡɪɚɛɨɬɤɚ ɢɟɪɚɪɯɢɢ ɚɛɫɬɪɚɤɬɧɵɯ ɢ ɤɨɧɤɪɟɬɧɵɯ ɤɥɚɫɫɨɜ
ɩɪɟɞɫɬɚɜɥɹɸɳɢɯ
ɡɚɞɚɧɧɭɸ
ɩɪɟɞɦɟɬɧɭɸ
ɨɛɥɚɫɬɶ
ɢ
ɢɧɬɟɪɚɤɬɢɜɧɨɝɨ ɩɪɢɥɨɠɟɧɢɹ ɞɟɦɨɧɫɬɪɢɪɭɸɳɟɝɨ ɪɚɛɨɬɭ
ɦɟɯɚɧɢɡɦɨɜ ɧɚɫɥɟɞɨɜɚɧɢɹ ɩɨɥɢɦɨɪɮɢɡɦɚ ɢ ɩɟɪɟɝɪɭɠɟɧɧɵɯ
ɨɩɟɪɚɬɨɪɨɜɜɪɚɡɪɚɛɨɬɚɧɧɨɣɢɟɪɚɪɯɢɢɤɥɚɫɫɨɜ
ȼɵɜɨɞɨɛɴɟɤɬɨɜɢɫɩɢɫɤɚɨɛɴɟɤɬɨɜɤɥɚɫɫɚɜɮɚɣɥɢɢɯɜɜɨɞ
ɢɡ ɮɚɣɥɚ ɫ ɩɪɢɦɟɧɟɧɢɟɦ ɤɥɚɫɫɨɜ ɮɚɣɥɨɜɵɯ ɩɨɬɨɤɨɜ
ɂɫɩɨɥɶɡɨɜɚɧɢɟɲɚɛɥɨɧɨɜɤɥɚɫɫɨɜɈɛɪɚɛɨɬɤɚɢɫɤɥɸɱɟɧɢɣ
Ʌɚɛɨɪɚɬɨɪɧɚɹ ɪɚɛɨɬɚ ʋ ɩɨɞɪɨɛɧɨ ɨɩɢɫɚɧɚ ɧɢɠɟ ɉɪɢ ɟɟ
ɜɵɩɨɥɧɟɧɢɢ ɪɟɤɨɦɟɧɞɭɟɬɫɹ ɢɫɩɨɥɶɡɨɜɚɬɶ ɞɨɩɨɥɧɢɬɟɥɶɧɭɸ
ɥɢɬɟɪɚɬɭɪɭ >±@ ɂɧɞɢɜɢɞɭɚɥɶɧɵɟ ɡɚɞɚɧɢɹ ɤ ɥɚɛɨɪɚɬɨɪɧɵɦ
ɪɚɛɨɬɚɦ ʋ ɢ ɢ ɞɟɬɚɥɶɧɵɟ ɭɤɚɡɚɧɢɹ ɩɨ ɢɯ ɜɵɩɨɥɧɟɧɢɸ
ɜɵɞɚɸɬɫɹ ɫɬɭɞɟɧɬɚɦ ɜɨ ɜɪɟɦɹ ɡɚɧɹɬɢɣ ɉɪɢ ɜɵɩɨɥɧɟɧɢɢ ɷɬɢɯ
ɥɚɛɨɪɚɬɨɪɧɵɯ ɪɚɛɨɬ ɫɥɟɞɭɟɬ ɢɫɩɨɥɶɡɨɜɚɬɶ ɭɱɟɛɧɭɸ ɥɢɬɟɪɚɬɭɪɭ
[6±[email protected]ɢɤɨɧɫɩɟɤɬɥɟɤɰɢɣ
5
1.3. ɋɢɫɬɟɦɚɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹQt
Qt ± ɷɬɨ ɢɧɫɬɪɭɦɟɧɬɚɥɶɧɚɹ ɫɢɫɬɟɦɚ ɜɢɡɭɚɥɶɧɨɝɨ ɨɛɴɟɤɬɧɨɨɪɢɟɧɬɢɪɨɜɚɧɧɨɝɨ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɞɥɹ ɛɵɫɬɪɨɣ ɪɚɡɪɚɛɨɬɤɢ
ɩɪɢɥɨɠɟɧɢɣ ɥɸɛɨɣ ɫɥɨɠɧɨɫɬɢ. Qt ɩɪɟɞɨɫɬɚɜɥɹɟɬ ɧɚɛɨɪ
ɛɢɛɥɢɨɬɟɤ ɫɪɟɞɫɬɜɚ ɪɚɡɪɚɛɨɬɤɢ ɬɟɫɬɢɪɨɜɚɧɢɹ ɢ ɨɬɥɚɞɤɢ
ɩɪɢɥɨɠɟɧɢɣ ɜɤɥɸɱɚɹ ɛɨɥɶɲɭɸ ɛɢɛɥɢɨɬɟɤɭ ɤɨɦɩɨɧɟɧɬɨɜ
ɤɨɦɩɥɟɤɬ ɢɧɫɬɪɭɦɟɧɬɨɜ ɩɪɨɟɤɬɢɪɨɜɚɧɢɹ ɲɚɛɥɨɧɵ ɩɪɢɥɨɠɟɧɢɣ
ɢ ɮɨɪɦ ɞɨɤɭɦɟɧɬɚɰɢɸ ɗɬɢ ɫɪɟɞɫɬɜɚ ɭɩɪɨɳɚɸɬ ɫɨɡɞɚɧɢɟ
ɩɪɨɬɨɬɢɩɚ ɢ ɫɨɤɪɚɳɚɸɬ ɜɪɟɦɹ ɪɚɡɪɚɛɨɬɤɢ ɩɪɨɝɪɚɦɦɵ Qt
ɩɨɡɜɨɥɹɟɬ ɡɚɩɭɫɤɚɬɶ ɧɚɩɢɫɚɧɧɨɟ ɉɈ ɜ ɛɨɥɶɲɢɧɫɬɜɟ
ɫɨɜɪɟɦɟɧɧɵɯ ɨɩɟɪɚɰɢɨɧɧɵɯ ɫɢɫɬɟɦ Ɉɋ ɩɭɬɟɦ ɤɨɦɩɢɥɹɰɢɢ
ɩɪɨɟɤɬɨɜ ɞɥɹ ɤɚɠɞɨɣ Ɉɋ ɛɟɡ ɢɡɦɟɧɟɧɢɹ ɢɫɯɨɞɧɨɝɨ ɤɨɞɚ
ȼɤɥɸɱɚɟɬ ɜ ɫɟɛɹ ɜɫɟ ɨɫɧɨɜɧɵɟ ɫɪɟɞɫɬɜɚ ɤɨɬɨɪɵɟ ɦɨɝɭɬ
ɩɨɬɪɟɛɨɜɚɬɶɫɹ ɩɪɢ ɪɚɡɪɚɛɨɬɤɟ ɩɪɢɤɥɚɞɧɨɝɨ ɩɪɨɝɪɚɦɦɧɨɝɨ
ɨɛɟɫɩɟɱɟɧɢɹ
6
2. Ɉɛɡɨɪɫɪɟɞɵɪɚɡɪɚɛɨɬɤɢ
Ɂɧɚɤɨɦɫɬɜɨɫ4tɫɢɝɧɚɥɵɢɫɥɨɬɵ
ɉɪɨɰɟɫɫɭɫɬɚɧɨɜɤɢQt SDK ɨɬɤɪɵɬɨɣɛɟɫɩɥɚɬɧɨɣɜɟɪɫɢɢɧɚ
ɤɨɧɤɪɟɬɧɭɸɈɋ ɦɨɠɧɨɧɚɣɬɢɜɥɢɬɟɪɚɬɭɪɟ>-5].
ɉɪɟɠɞɟɱɟɦɩɟɪɟɯɨɞɢɬɶɤɡɚɩɭɫɤɭ4W&UHDWRU ɪɟɤɨɦɟɧɞɭɟɬɫɹ
ɨɡɧɚɤɨɦɢɬɶɫɹ ɫ ɨɫɧɨɜɚɦɢ ɩɪɨɝɪɚɦɦɢɪɨɜɚɧɢɹ ɜ 4W ɛɟɡ
ɢɫɩɨɥɶɡɨɜɚɧɢɹɝɪɚɮɢɱɟɫɤɨɝɨɪɟɞɚɤɬɨɪɚ>@ɝɥɚɜɵ-ɢɥɢ>@
ɝɥɚɜɚ ɢɥɢ ɧɚ ɜɜɨɞɧɨɣ ɥɟɤɰɢɢ Ɂɞɟɫɶ ɩɪɢɜɟɞɟɧɵ ɧɚɢɛɨɥɟɟ
ɜɚɠɧɵɟɫɜɟɞɟɧɢɹ
Ɉɬɥɢɱɢɬɟɥɶɧɚɹ ɨɫɨɛɟɧɧɨɫɬɶ 4W ɫɨɫɬɨɢɬ ɜ ɢɫɩɨɥɶɡɨɜɚɧɢɢ
ɩɪɟɞɜɚɪɢɬɟɥɶɧɨɣ ɫɢɫɬɟɦɵ ɨɛɪɚɛɨɬɤɢ ɢɫɯɨɞɧɨɝɨ ɤɨɞɚ Meta
Object Compiler, MOC). MOC ɹɜɥɹɟɬɫɹ ɩɨɫɪɟɞɧɢɤɨɦ ɦɟɠɞɭ
ɧɟɤɨɬɨɪɵɦɢ ɨɫɨɛɵɦɢ ɜɨɡɦɨɠɧɨɫɬɹɦɢ ɛɢɛɥɢɨɬɟɤɢ Qt ɢ
ɫɬɚɧɞɚɪɬɧɵɦɢ ɤɨɦɩɢɥɹɬɨɪɚɦɢ C++. MOC ɩɨɡɜɨɥɹɟɬ ɜɜɨɞɢɬɶ ɜ
ɹɡɵɤ C++ ɧɨɜɵɟ ɩɨɧɹɬɢɹ ɢ ɩɪɢɧɰɢɩɵ ɧɚɩɪɢɦɟɪ ɫɥɨɬɵ ɢ
ɫɢɝɧɚɥɵ. ɉɪɟɩɪɨɰɟɫɫɨɪ 02& ɢɳɟɬ ɜ ɡɚɝɨɥɨɜɨɱɧɵɯ ɮɚɣɥɚɯ ɧɚ
& ɨɩɢɫɚɧɢɹ ɤɥɚɫɫɨɜ ɫɨɞɟɪɠɚɳɢɟ ɦɚɤɪɨɫ Q_OBJECT ɢ
ɫɨɡɞɚɟɬ ɞɨɩɨɥɧɢɬɟɥɶɧɵɣ ɢɫɯɨɞɧɵɣ ɮɚɣɥ ɧɚ & ɫɨɞɟɪɠɚɳɢɣ
ɦɟɬɚɨɛɴɟɤɬɧɵɣɤɨɞɤɨɬɨɪɵɣɞɨɫɬɭɩɟɧɞɥɹɤɨɦɩɢɥɹɬɨɪɨɜ.
ȼ 4W ɢɫɩɨɥɶɡɭɟɬɫɹ ɨɛɴɟɤɬɧɚɹ ɦɨɞɟɥɶ ɞɥɹ ɷɬɨɝɨ ɜɜɨɞɢɬɫɹ
ɛɚɡɨɜɵɣ ɞɥɹ ɦɧɨɝɢɯ ɤɥɚɫɫɨɜ ɤɥɚɫɫ QObject ȼɚɠɧɨɣ
ɨɫɨɛɟɧɧɨɫɬɶɸ ɤɥɚɫɫɚ QObject
ɹɜɥɹɟɬɫɹ ɜɨɡɦɨɠɧɨɫɬɶ
ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɦɟɯɚɧɢɡɦɚ ɫɢɝɧɚɥɨɜ ɢ ɫɥɨɬɨɜ ɉɪɢɧɰɢɩɵ ɈɈɉ
ɜɵɞɚɸɬɫɹ ɧɚ ɥɟɤɰɢɹɯ ɩɨɷɬɨɦɭ ɡɞɟɫɶ ɧɟ ɩɪɢɜɨɞɹɬɫɹ Ɉɞɧɚɤɨ
ɦɟɯɚɧɢɡɦ ɫɢɝɧɚɥɨɜ ɢ ɫɥɨɬɨɜ ɹɜɥɹɟɬɫɹ ɨɬɥɢɱɢɟɦ 4W ɤɨɬɨɪɨɟ
ɞɟɥɚɟɬ ɹɡɵɤ C++ ɟɳɟ ɛɨɥɟɟ ɩɨɞɯɨɞɹɳɢɦ ɩɨɞ ɈɈɉ ɉɪɢɱɢɧɵ
ɜɨɡɧɢɤɧɨɜɟɧɢɹ ɷɬɨɝɨ ɦɟɯɚɧɢɡɦɚ ɢ ɟɝɨ ɩɪɟɢɦɭɳɟɫɬɜɚ
ɨɛɫɬɨɹɬɟɥɶɧɨ ɨɩɢɫɚɧɵ ɜ > ɝɥɚɜɚ @ ȼɨɡɦɨɠɧɨ ɷɬɨɬ ɦɟɯɚɧɢɡɦ
ɥɭɱɲɟɫɨɨɬɜɟɬɫɬɜɭɟɬɬɪɟɛɨɜɚɧɢɹɦɈɈɉɱɟɦɦɟɯɚɧɢɡɦɮɭɧɤɰɢɣ
ɨɛɪɚɬɧɨɝɨɜɵɡɨɜɚɢɫɩɨɥɶɡɭɟɦɵɣɜ:LQGRZs API.
ɉɪɢɦɟɪɟɫɬɶɷɤɪɚɧɧɚɹɮɨɪɦɚɫɤɧɨɩɤɚɦɢɢɩɨɥɹɦɢɜɵɜɨɞɚɢ
ɬɞ ɢ ɟɫɬɶ ɧɟɤɨɬɨɪɵɟ ɞɟɣɫɬɜɢɹ ɥɨɝɢɤɚ ɪɚɛɨɬɵ ɜɵɡɵɜɚɟɦɵɟ
ɮɨɪɦɨɣ ɪɚɫɱɟɬɵ ɫɨɟɞɢɧɟɧɢɹ ɫ ȻȾ ɱɬɟɧɢɟ ɮɚɣɥɨɜ ɢ ɬɩ
ɈɱɟɜɢɞɧɨɱɬɨɩɨɩɪɢɧɰɢɩɚɦɈɈɉɮɨɪɦɚɞɨɥɠɧɚɛɵɬɶɜɨɞɧɨɦ
ɤɥɚɫɫɟɨɛɴɟɤɬɵɪɟɚɥɢɡɭɸɳɢɟɥɨɝɢɤɭ, ɜɞɪɭɝɢɯ
ɉɪɢ ɩɨɞɯɨɞɟ ɛɟɡ ɫɢɝɧɚɥɨɜɫɥɨɬɨɜ ɩɪɢɲɥɨɫɶ ɛɵ ɧɚɩɪɢɦɟɪ
ɜɤɥɸɱɢɬɶ ɪɚɛɨɱɢɣ ɤɥɚɫɫ ɤɚɤ ɱɥɟɧ ɤɥɚɫɫɚ ɮɨɪɦɵ ɱɬɨɛɵ ɜ ɤɨɞɟ
ɨɛɪɚɛɨɬɱɢɤɚ ɤɧɨɩɤɢ ɜɵɡɵɜɚɬɶ ɟɝɨ ɦɟɬɨɞɵ ɇɨ ɟɫɥɢ ɢ ɪɚɛɨɱɢɣ
ɤɥɚɫɫɞɨɥɠɟɧɢɦɟɬɶɞɨɫɬɭɩɤɮɨɪɦɟɧɚɩɪɢɦɟɪɤɩɨɥɹɦɜɵɜɨɞɚ"
ȼ ɟɝɨ ɦɟɬɨɞɚɯ ɦɨɠɧɨ ɛɵɥɨ ɛɵ ɢɫɩɨɥɶɡɨɜɚɬɶ ɡɚɤɪɵɬɵɟ ɱɥɟɧɵ
ɤɥɚɫɫɚ ɮɨɪɦɵ ȼ ɥɸɛɨɦ ɫɥɭɱɚɟ ɞɜɚ ɤɥɚɫɫɚ ɨɤɚɡɚɥɢɫɶ ɛɵ
7
ɫɥɢɲɤɨɦɬɟɫɧɨɩɟɪɟɩɥɟɬɟɧɵɬɨɟɫɬɶɫɜɹɡɶɦɟɠɞɭɧɢɦɢɛɵɥɚɛɵ
ɧɚɦɧɨɝɨ ɫɢɥɶɧɟɟ ɱɟɦ ɷɬɨ ɫɥɟɞɨɜɚɥɨ ɛɵ ɢɡ ɥɨɝɢɤɢ ɢɯ
ɜɡɚɢɦɨɫɜɹɡɢȺɟɫɥɢɤɨɞɪɚɛɨɱɟɝɨɤɥɚɫɫɚɢɤɥɚɫɫɚɮɨɪɦɵɩɢɲɭɬ
ɪɚɡɧɵɟ ɩɪɨɝɪɚɦɦɢɫɬɵ" ȿɫɥɢ ɧɭɠɧɨ ɡɚɦɟɧɢɬɶ ɷɬɭ ɮɨɪɦɭ ɧɚ
ɞɪɭɝɭɸ ɢɥɢ ɜɧɟɫɬɢ ɜ ɧɟɟ ɞɪɭɝɭɸ ɮɭɧɤɰɢɨɧɚɥɶɧɨɫɬɶ" ȼɫɟ ɷɬɨ
ɛɵɥɨ ɛɵ ɩɪɨɛɥɟɦɚɬɢɱɧɨ ɫɞɟɥɚɬɶ ɢɡ-ɡɚ ɫɢɥɶɧɨɣ ɫɜɹɡɢ ɤɥɚɫɫɨɜ
Ɍɚɤɠɟ ɫɢɝɧɚɥɵ ɢ ɫɥɨɬɵ ɩɨɥɟɡɧɵ ɜ ɫɥɭɱɚɟ ɢɫɩɨɥɶɡɨɜɚɧɢɹ ɞɥɹ
ɤɚɤɨɝɨ-ɥɢɛɨɨɛɴɟɤɬɚɨɬɞɟɥɶɧɨɝɨɩɨɬɨɤɚ
ɉɨɷɬɨɦɭ ɢ ɜɜɟɞɟɧ ɦɟɯɚɧɢɡɦ ɫɢɝɧɚɥɨɜ ɢ ɫɥɨɬɨɜ ɤɨɬɨɪɵɣ
ɛɚɡɢɪɭɟɬɫɹ ɧɚ ɩɪɢɧɰɢɩɟ ɈɈɉ ©Ɉɛɴɟɤɬɵ ɜɡɚɢɦɨɞɟɣɫɬɜɭɸɬ
ɩɨɫɵɥɚɹ ɢ ɩɨɥɭɱɚɹ ɫɨɨɛɳɟɧɢɹª ɋɢɝɧɚɥ ± ɷɬɨ ɩɨɫɵɥɤɚ
ɫɨɨɛɳɟɧɢɹɚɫɥɨɬ± ɷɬɨɩɪɢɟɦɧɢɤɫɢɝɧɚɥɨɜɁɜɨɧɨɤɬɟɥɟɮɨɧɚ±
ɫɢɝɧɚɥ ɫɩɨɫɨɛɧɨɫɬɶ ɱɟɥɨɜɟɤɚ ɭɫɥɵɲɚɬɶ ɡɜɨɧɨɤ ± ɷɬɨ ɟɝɨ ɫɥɨɬ
ɋɢɝɧɚɥ ɦɨɠɧɨ ɩɨɞɤɥɸɱɢɬɶ ɤ ɪɚɡɥɢɱɧɨɦɭ ɱɢɫɥɭ ɫɥɨɬɨɜ ɪɚɡɧɵɯ
ɨɛɴɟɤɬɨɜɩɪɢɱɟɦɨɛɴɟɤɬɜɵɫɵɥɚɸɳɢɣɫɢɝɧɚɥ, ɧɢɱɟɝɨɧɟɡɧɚɟɬ
ɨ ɬɨɦ ɤɬɨ ɟɝɨ ɩɨɥɭɱɢɬ ± ɨɛ ɷɬɨɦ ɡɧɚɟɬ ɬɨɥɶɤɨ ɪɚɡɪɚɛɨɬɱɢɤ
ɫɨɟɞɢɧɹɸɳɢɣ ɫɢɝɧɚɥɵ ɨɞɧɢɯ ɨɛɴɟɤɬɨɜ ɫɨ ɫɥɨɬɚɦɢ ɞɪɭɝɢɯ
Ɉɛɴɟɤɬ ɫɥɨɬ ɤɨɬɨɪɨɝɨ ɩɨɥɭɱɢɥ ɫɢɝɧɚɥ ɦɨɠɟɬ ɭɡɧɚɬɶ
ɨɬɩɪɚɜɢɬɟɥɹ ɱɟɪɟɡ ɦɟɬɨɞ sender() ɜɨɡɜɪɚɳɚɸɳɢɣ ɭɤɚɡɚɬɟɥɶ ɧɚ
ɨɛɴɟɤɬ-ɨɬɩɪɚɜɢɬɟɥɹ
Ɍɚɤɨɟ ɫɨɟɞɢɧɟɧɢɟ ɛɭɞɟɬ ɪɚɛɨɬɚɬɶ ɧɟɦɧɨɝɨ ɦɟɞɥɟɧɧɟɟ ɱɟɦ
ɜɵɡɨɜ ɮɭɧɤɰɢɣ ɧɨ ɞɥɹ ɛɨɥɶɲɢɧɫɬɜɚ ɧɟɤɪɢɬɢɱɧɵɯ ɤ ɜɪɟɦɟɧɢ
ɜɵɩɨɥɧɟɧɢɹ ɩɪɢɥɨɠɟɧɢɣ ɷɬɚ ɪɚɡɧɢɰɚ ɧɟ ɢɦɟɟɬ ɡɧɚɱɟɧɢɹ. ȼ
ɨɫɬɚɥɶɧɨɦɫɥɨɬɵɨɱɟɧɶɩɨɯɨɠɢɧɚɨɛɵɱɧɵɟɦɟɬɨɞɵɤɪɨɦɟɬɨɝɨ
ɱɬɨ ɨɧɢ ɧɟ ɦɨɝɭɬ ɫɨɞɟɪɠɚɬɶ ɩɚɪɚɦɟɬɪɨɜ ɩɨ ɭɦɨɥɱɚɧɢɸ ɢ
ɹɜɥɹɬɶɫɹ ɫɬɚɬɢɱɟɫɤɢɦɢ ɩɨɫɥɟɞɧɟɟ ɫɜɹɡɚɧɨ ɫ ɧɟɨɛɯɨɞɢɦɨɫɬɶɸ
ɫɨɟɞɢɧɹɬɶɫɢɝɧɚɥɫɨɫɥɨɬɨɦɤɨɧɤɪɟɬɧɨɝɨɫɨɡɞɚɧɧɨɝɨɨɛɴɟɤɬɚ
Ɉɫɧɨɜɧɵɟɫɜɨɣɫɬɜɚɫɨɟɞɢɧɟɧɢɣɫɢɝɧɚɥɨɜɢɫɥɨɬɨɜ
- ɤɫɢɝɧɚɥɭɦɨɠɧɨɩɨɞɤɥɸɱɚɬɶɧɟɫɤɨɥɶɤɨɫɥɨɬɨɜ
- ɫɥɨɬɦɨɠɧɨɩɨɞɤɥɸɱɚɬɶɤɧɟɫɤɨɥɶɤɢɦɫɢɝɧɚɥɚɦ
- ɫɢɝɧɚɥ ɦɨɠɧɨ ɩɨɞɤɥɸɱɢɬɶ ɤ ɞɪɭɝɨɦɭ ɫɢɝɧɚɥɭ ɜ ɷɬɨɦ
ɫɥɭɱɚɟ ɩɪɢ ɝɟɧɟɪɚɰɢɢ ɩɟɪɜɨɝɨ ɫɢɝɧɚɥɚ ɛɭɞɟɬ ɫɝɟɧɟɪɢɪɨɜɚɧ ɢ
ɜɬɨɪɨɣɧɨɧɟɧɚɨɛɨɪɨɬ
- ɫɜɹɡɶɦɨɠɧɨɭɫɬɚɧɨɜɢɬɶɢɪɚɡɨɪɜɚɬɶɜɥɸɛɨɟɜɪɟɦɹ
- ɩɚɪɚɦɟɬɪɵ ɫɢɝɧɚɥɚ ɢ ɫɥɨɬɚ ɞɨɥɠɧɵ ɡɚɞɚɜɚɬɶɫɹ ɜ
ɨɞɢɧɚɤɨɜɨɦ ɩɨɪɹɞɤɟ ɢ ɢɦɟɬɶ ɨɞɢɧɚɤɨɜɵɣ ɬɢɩ ɟɫɥɢ ɭ ɫɢɝɧɚɥɚ
ɛɨɥɶɲɟ ɩɚɪɚɦɟɬɪɨɜ ɱɟɦ ɭ ɫɥɨɬɚ ɞɨɩɨɥɧɢɬɟɥɶɧɵɟ ɩɚɪɚɦɟɬɪɵ
ɛɭɞɭɬɢɝɧɨɪɢɪɨɜɚɬɶɫɹ
- ɩɪɢɭɧɢɱɬɨɠɟɧɢɢɨɛɴɟɤɬɚɜɫɟɫɜɹɡɚɧɧɵɟɫɧɢɦɫɨɟɞɢɧɟɧɢɹ
ɛɭɞɭɬɭɧɢɱɬɨɠɟɧɵɚɜɬɨɦɚɬɢɱɟɫɤɢ
ɉɨɥɧɨɫɬɶɸɢɡɛɚɜɢɬɶɫɹɨɬɥɢɲɧɢɯɫɜɹɡɟɣɦɟɯɚɧɢɡɦɩɨɡɜɨɥɹɟɬ
ɧɟ ɜɨ ɜɫɟɯ ɫɥɭɱɚɹɯ ɢɧɨɝɞɚ ɧɚɩɪɢɦɟɪ ɜɫɟ ɠɟ ɩɪɢɯɨɞɢɬɫɹ
ɢɫɩɨɥɶɡɨɜɚɬɶ ɭɤɚɡɚɬɟɥɶ ɧɚ ɮɨɪɦɭ, ɧɨ ɡɧɚɱɢɬɟɥɶɧɨ ɢɯ
8
ɫɨɤɪɚɳɚɟɬ ȼ ɯɨɞɟ ɜɵɩɨɥɧɟɧɢɹ ɩɟɪɨɜɨɣ ɥɚɛɨɪɚɬɨɪɧɨɣ ɪɚɛɨɬɵ
ɷɬɨɬɦɟɯɚɧɢɡɦɛɭɞɟɬɪɚɡɨɛɪɚɧɢɩɪɢɦɟɧɟɧ
Ɋɚɫɫɦɨɬɪɢɦ ɩɪɨɫɬɨɣ ɩɪɢɦɟɪ ɟɫɬɶ ɨɛɴɟɤɬ ɩɨɫɵɥɚɸɳɢɣ
ɫɢɝɧɚɥɵɧɟɫɭɳɢɟɧɟɤɨɬɨɪɭɸɢɧɮɨɪɦɚɰɢɸɜɜɢɞɟɰɟɥɨɝɨɱɢɫɥɚ,
ɢ ɨɛɴɟɤɬ ɤɨɬɨɪɵɟ ɷɬɢ ɫɢɝɧɚɥɵ ɩɨɥɭɱɚɟɬ ɇɟɨɛɯɨɞɢɦɨ
ɪɟɚɥɢɡɨɜɚɬɶɤɥɚɫɫɵɞɥɹɩɨɫɵɥɤɢ ɢ ɩɪɢɟɦɚ ɫɢɝɧɚɥɨɜ ɬɚɤ ɱɬɨɛɵ
ɢɯ ɪɟɚɥɢɡɚɰɢɹ ɨɞɧɨɝɨ ɤɥɚɫɫɚ ɧɟ ɡɚɜɢɫɟɥɚ ɛɵ ɨɬ ɞɪɭɝɨɝɨ ɚ
ɨɛɴɟɤɬɵɤɥɚɫɫɨɜɧɟɛɵɥɢɛɵɫɜɹɡɚɧɵɧɢɱɟɦɤɪɨɦɟɫɨɟɞɢɧɟɧɢɹ
ɫɢɝɧɚɥɨɜɢɫɥɨɬɨɜ
Ʉɨɞɤɥɚɫɫɚɢɫɬɨɱɧɢɤɚɫɢɝɧɚɥɨɜ
class MySender : public QObject {
Q_OBJECTɦɚɤɪɨɫO_OBJECT ɧɟɨɛɯɨɞɢɦɞɥɹɤɥɚɫɫɨɜɫɨɞɟɪɠɚɳɢɯ
ɫɢɝɧɚɥɵɢɫɥɨɬɵ
public:
void sendSignal(int x);
signals:
void signal1(const int);
};
void MySender:: sendSignal(int x) {
emit signal1(x);//emit ɨɡɧɚɱɚɟɬɜɵɫɥɚɬɶɫɢɝɧɚɥ
}
ɤɨɞ ɤɥɚɫɫ ɩɪɢɟɦɧɢɤɚ:
class MyReceiver : public QObject { Q_OBJECT
public slots:
void slot1(int x);
};
void MyReceiver::slot1(int x) {
qDebug()<<x<<sender()->objectName();
//qDebug ɩɨɡɜɨɥɹɟɬ ɜɵɩɨɥɧɹɬɶ ɜɵɜɨɞ ɫɨɨɛɳɟɧɢɣ
ɬɟɪɦɢɧɚɥɩɪɢɨɬɥɚɞɤɟ
}
ɩɨɫɥɟɞɧɢɦɩɪɢɜɟɞɟɧɤɨɞɮɭɧɤɰɢɢɞɥɹɞɟɦɨɧɫɬɪɚɰɢɢɫɜɹɡɢ
int main()
{
MySender *sender = new MySender();
MyReceiver *receiver = new MyReceiver();
seneder->setObjectName("sender");
sender->sendSignal(10);
ɫɢɝɧɚɥɧɟɛɭɞɟɬɩɨɥɭɱɟɧɬɚɤɤɚɤɟɳɟɧɟɬɫɨɟɞɢɧɟɧɢɹ
QObject::connect(sender,SIGNAL(signal1(int)),
receiver,SLOT(slot1(int)));
sender->sendSignal(100);
ɜɬɟɪɦɢɧɚɥɟɛɭɞɟɬɜɵɜɟɞɟɧɨsender1"
QObject::disconnect(sender,SIGNAL(signal1(int)),
receiver,SLOT(slot1(int)));
sender->sendSignal(100);
ɫɢɝɧɚɥɧɟɛɭɞɟɬɩɨɥɭɱɟɧɬɚɤɤɚɤɭɠɟɧɟɬɫɨɟɞɢɧɟɧɢɹ
return 0;
}
9
ɜ
ȼ ɤɨɞɟ ɤɥɚɫɫɨɜ ɢɫɬɨɱɧɢɤɚ ɢ ɩɪɢɟɦɧɢɤɚ ɧɟɬ ɧɢɤɚɤɢɯ
ɜɡɚɢɦɧɵɯ ɫɜɹɡɟɣ ɫɜɹɡɶ ɦɟɠɞɭ ɨɛɴɟɤɬɚɦɢ ɤɥɚɫɫɚ
ɭɫɬɚɧɚɜɥɢɜɚɟɬɫɹ ɬɚɤ ɠɟ ɧɟ ɜɧɭɬɪɢ ɢɯ ɪɟɚɥɢɡɚɰɢɣ Ʉ ɨɞɧɨɦɭ
ɨɛɴɟɤɬɭ ɢɫɬɨɱɧɢɤɭ ɦɨɠɧɨ ɩɨɞɤɥɸɱɢɬɶ ɧɟɫɤɨɥɶɤɨ ɨɛɴɟɤɬɨɜ
ɩɪɢɟɦɧɢɤɨɜ ɨɞɢɧ ɩɪɢɟɦɧɢɤ ɦɨɠɟɬ ɛɵɬɶ ɫɨɟɞɢɧɟɧ ɫ
ɧɟɫɤɨɥɶɤɢɦɢ ɢɫɬɨɱɧɢɤɚɦɢ Ɋɟɚɥɢɡɚɰɢɹ ɫɢɝɧɚɥɨɜ ɧɢɤɨɝɞɚ ɧɟ
ɩɪɨɩɢɫɵɜɚɟɬɫɹɜɤɨɞɟɟɟɛɟɪɟɬɧɚɫɟɛɹMOC.
2.2. Ɂɚɩɭɫɤ ɫɢɫɬɟɦɵ Qt Creator
ȼɵ ɦɨɠɟɬɟ ɡɚɩɭɫɬɢɬɶ Qt Creator ɨɞɧɢɦ ɢɡ ɫɥɟɞɭɸɳɢɯ
ɫɩɨɫɨɛɨɜ
± ɧɚɪɚɛɨɱɟɦɫɬɨɥɟɞɜɚɠɞɵɳɟɥɤɧɢɬɟɡɧɚɱɨɤQt Creator;
± ɜɵɛɟɪɢɬɟɩɭɧɤɬɦɟɧɸɉɭɫɤ o ɉɪɨɝɪɚɦɦɵ o Qt Creator by
Nokia o Qt Creator;
± ɜɵɛɟɪɢɬɟɩɭɧɤɬɦɟɧɸɉɭɫɤo ȼɵɩɨɥɧɢɬɶɚɡɚɬɟɦɜɜɟɞɢɬɟ
qt creator;
± ɜ ɩɚɩɤɟ Qt\qtcreator-x.x.x\bin ɢɥɢ QtSDK\QtCreator\bin
ɞɜɚɠɞɵɳɟɥɤɧɢɬɟɮɚɣɥ qtcreator.exe.
ȼ ɫɥɟɞɭɸɳɢɯ ɪɚɡɞɟɥɚɯ ɩɪɢɜɨɞɢɬɫɹ ɪɭɤɨɜɨɞɫɬɜɨ ɩɨ ɫɢɫɬɟɦɟ
4W &UHDWRU ɭɩɪɨɳɚɸɳɟɣ ɧɚɩɢɫɚɧɢɟ ɩɪɢɥɨɠɟɧɢɣ Ɋɭɤɨɜɨɞɫɬɜɨ
ɨɫɧɨɜɚɧɨɧɚɦɚɬɟɪɢɚɥɚɯɪɟɫɭɪɫɚCrossplatform.ru.
4W&UHDWRUɜɤɥɸɱɚɟɬɛɨɥɶɲɨɟɱɢɫɥɨɩɨɥɟɡɧɵɯɨɫɨɛɟɧɧɨɫɬɟɣ:
- ɬɟɤɫɬɨɜɵɣ ɪɟɞɚɤɬɨɪ ɩɪɟɞɨɫɬɚɜɥɹɟɬ ɧɚɜɢɝɚɰɢɸ ɩɨɞɞɟɪɠɤɭ
ɫɢɧɬɚɤɫɢɫɚɢɞɨɩɨɥɧɟɧɢɹ ɤɨɞɚ;
- ɦɚɫɬɟɪ ɝɟɧɟɪɚɰɢɢ ɩɪɨɟɤɬɨɜ ɩɨɡɜɨɥɹɟɬ ɫɨɡɞɚɜɚɬɶ ɪɚɡɥɢɱɧɵɟ
ɜɢɞɵɩɪɨɟɤɬɨɜɢɫɩɨɥɶɡɭɹɲɚɛɥɨɧɵ
- ɞɨɤɭɦɟɧɬɚɰɢɹɢɧɬɟɝɪɢɪɨɜɚɧɚɜQt Creatorɜɩɪɨɰɟɫɫɪɚɛɨɬɵ
ɦɨɠɧɨɛɵɫɬɪɨɩɟɪɟɣɬɢɤɫɩɪɚɜɤɟ
- ɮɨɪɦɵ ɝɪɚɮɢɱɟɫɤɨɝɨ ɢɧɬɟɪɮɟɣɫɚ ɩɨɥɶɡɨɜɚɬɟɥɹ ɦɨɠɧɨ
ɛɵɫɬɪɨɩɪɨɟɤɬɢɪɨɜɚɬɶɛɥɚɝɨɞɚɪɹɢɧɫɬɪɭɦɟɧɬɭQt Designer;
- ɩɪɢɥɨɠɟɧɢɹ ɦɨɠɧɨ ɨɬɥɚɠɢɜɚɬɶ ɫ ɢɫɩɨɥɶɡɨɜɚɧɢɟɦ
ɝɪɚɮɢɱɟɫɤɨɝɨ ɢɧɬɟɪɮɟɣɫɚ ɤ *18 V\PEROLF GHEXJJHU *'% ɢ
Microsoft Console Debugger (CDB);
- Qt SDK ɜɤɥɸɱɚɟɬɜɫɟɛɹɭɬɢɥɢɬɵɞɥɹɛɵɫɬɪɨɣɥɨɤɚɥɢɡɚɰɢɢ
ɩɪɢɥɨɠɟɧɢɣ
10
2.3. Ʉɪɚɬɤɢɣ ɨɛɡɨɪ4W&UHDWRU
ȼ ɞɚɧɧɨɦ ɨɛɡɨɪɟ ɢɫɩɨɥɶɡɨɜɚɧɵ ɦɚɬɟɪɢɚɥɵ [1]. ɇɚ ɪɢɫɭɧɤɟ
ɩɨɤɚɡɚɫɧɢɦɨɤɷɤɪɚɧɚQt Creator ɜɪɟɠɢɦɟɉɪɚɜɤɚ.
Ɂɚɦɟɱɚɧɢɟ. ȼ ɪɚɡɥɢɱɧɵɯ ɜɟɪɫɢɹɯ Qt Creator ɦɨɝɭɬ ɛɵɬɶ
ɢɡɦɟɧɟɧɢɹ ɜ ɪɚɫɩɨɥɨɠɟɧɢɢ ɢ ɧɚɡɜɚɧɢɢ ɷɥɟɦɟɧɬɨɜ ɫɬɪɭɤɬɭɪɟ
ɦɟɧɸ ɢ ɩɚɪɚɦɟɬɪɚɯ ɉɨɷɬɨɦɭ ɩɪɢɜɟɞɟɧɧɵɟ ɫɤɪɢɧɲɨɬɵ ɢ
ɨɩɢɫɚɧɢɹ ɦɨɝɭɬ ɧɟ ɜɨ ɜɫɟɦ ɫɨɨɬɜɟɬɫɬɜɨɜɚɬɶ ɜɚɲɟɣ ɜɟɪɫɢɢ
ɯɨɬɹ ɩɪɢɧɰɢɩɢɚɥɶɧɵɯ ɨɬɥɢɱɢɣ ɜ ɜɟɪɫɢɹɯ ɫ ɨɞɢɧɚɤɨɜɵɦ
ɫɬɚɪɲɢɦɱɢɫɥɨɦ ɧɟɬɜɞɚɧɧɨɦɪɭɤɨɜɨɞɫɬɜɟɢɫɩɨɥɶɡɭɸɬɫɹQt 4
ɢQt Creator 2).
Ɋɢɫɭɧɨɤ ± ɈɤɧɨQt Creator
ȼ Qt Creator ɟɫɬɶ ɧɟɫɤɨɥɶɤɨ ɪɟɠɢɦɨɜ ɪɚɛɨɬɵ: ɇɚɱɚɥɨ,
Ɋɟɞɚɤɬɨɪɉɪɚɜɤɚ), ȾɢɡɚɣɧɈɬɥɚɞɤɚ, ɉɪɨɟɤɬɵ, Ⱥɧɚɥɢɡȼɵɜɨɞ
ɢɋɩɪɚɜɤɚ.
ɇɚɱɚɥɨ Ɉɬɨɛɪɚɠɚɟɬ ɷɤɪɚɧ ɩɪɢɜɟɬɫɬɜɢɹ ɩɨɡɜɨɥɹɹ ɛɵɫɬɪɨ
ɡɚɝɪɭɠɚɬɶ ɧɟɞɚɜɧɢɟ ɫɟɫɫɢɢ ɢɥɢ ɨɬɞɟɥɶɧɵɟ ɩɪɨɟɤɬɵ Ɂɞɟɫɶ ɠɟ
ɦɨɠɧɨɩɟɪɟɣɬɢɤɞɟɦɨɧɫɬɪɚɰɢɨɧɧɵɦɩɪɨɝɪɚɦɦɚɦɢɩɪɢɦɟɪɚɦ
Ɋɟɞɚɤɬɨɪ ɉɨɡɜɨɥɹɟɬ ɪɟɞɚɤɬɢɪɨɜɚɬɶ ɮɚɣɥɵ ɩɪɨɟɤɬɚ ɢ
ɢɫɯɨɞɧɵɯɤɨɞɨɜȻɨɤɨɜɚɹɩɚɧɟɥɶɫɥɟɜɚɩɪɟɞɨɫɬɚɜɥɹɟɬɪɚɡɥɢɱɧɵɟ
ɜɢɞɵ ɞɥɹ ɩɟɪɟɦɟɳɟɧɢɹ ɜ ɩɪɨɟɤɬɟ ɮɚɣɥɨɜɚɹ ɫɢɫɬɟɦɚ ɢɟɪɚɪɯɢɹ
ɮɚɣɥɨɜɜɯɨɞɹɳɢɯɜɩɪɨɟɤɬɨɛɡɨɪɤɥɚɫɫɨɜɢɬɞ
Ⱦɢɡɚɣɧ Ɋɟɠɢɦ ɞɥɹ ɜɢɡɭɚɥɶɧɨɣ ɪɚɛɨɬɵ ɫ ɮɨɪɦɚɦɢ
ɝɪɚɮɢɱɟɫɤɨɝɨɩɨɥɶɡɨɜɚɬɟɥɶɫɤɨɝɨɢɧɬɟɪɮɟɣɫɚ
11
Ɉɬɥɚɞɤɚ. ɂɧɫɬɪɭɦɟɧɬɵ ɢ ɧɚɫɬɪɨɣɤɢ ɞɥɹ ɨɬɥɚɞɤɢ
ɩɪɢɥɨɠɟɧɢɣ
ɉɪɨɟɤɬɵ ɉɨɡɜɨɥɹɟɬ ɧɚɫɬɪɨɢɬɶ ɷɬɚɩɵ ɫɛɨɪɤɢ ɢ ɡɚɩɭɫɤɚ
ɩɪɨɟɤɬɨɜɜɤɥɸɱɚɹɜɵɛɨɪɤɨɦɩɢɥɹɬɨɪɚɬɢɩɚɫɛɨɪɤɢɢɩɪɨɱɟɟ.
Ⱥɧɚɥɢɡ. ɂɧɫɬɪɭɦɟɧɬɞɥɹɨɬɥɚɞɤɢ
ɋɩɪɚɜɤɚɉɨɤɚɡɵɜɚɟɬɜɫɸɞɨɤɭɦɟɧɬɚɰɢɸɩɨɛɢɛɥɢɨɬɟɤɚɦQt
ɢQt Creator.
2.3.1 ɉɚɧɟɥɢɜɵɜɨɞɚ
ɉɚɧɟɥɶɡɚɞɚɱɜ4W&UHDWRUɦɨɠɟɬɨɬɨɛɪɚɠɚɬɶɨɞɧɭɢɡɱɟɬɵɪɟɯ
ɪɚɡɥɢɱɧɵɯ ɩɚɧɟɥɟɣ ȼɵɜɨɞ ɫɛɨɪɤɢ ɉɪɨɛɥɟɦɵ, Ɋɟɡɭɥɶɬɚɬɵ
ɩɨɢɫɤɚ, ȼɵɜɨɞ ɩɪɢɥɨɠɟɧɢɹ ɢ ȼɵɜɨɞ ɤɨɦɩɢɥɹɬɨɪɚ Ʉɨɧɫɨɥɶ
ɫɛɨɪɤɢɗɬɢɩɚɧɟɥɢɞɨɫɬɭɩɧɵɜɨɜɫɟɯɪɟɠɢɦɚɯ
ɉɚɧɟɥɶ ȼɵɜɨɞ ɫɛɨɪɤɢ (ɪɢɫɭɧɨɤ ) ɩɪɟɞɨɫɬɚɜɥɹɟɬ
ɫɨɨɛɳɟɧɢɹ ɨɛ ɨɲɢɛɤɚɯ ɢɥɢ ɩɪɟɞɭɩɪɟɠɞɟɧɢɹɯ. ɇɟɡɧɚɱɢɬɟɥɶɧɵɟ
ɫɨɨɛɳɟɧɢɹ ɤɨɦɩɢɥɹɬɨɪɚ ɦɨɝɭɬ ɛɵɬɶ ɩɪɨɩɭɳɟɧɵ ɤɪɨɦɟ ɬɨɝɨ
ɩɚɧɟɥɶɭɩɨɪɹɞɨɱɢɜɚɟɬ ɜɵɜɨɞ ɫɨɨɛɳɟɧɢɣ.
Ɋɢɫɭɧɨɤ± ȼɵɜɨɞɫɛɨɪɤɢ
ɉɚɧɟɥɶ Ɋɟɡɭɥɶɬɚɬɵ ɩɨɢɫɤɚ ɪɢɫɭɧɨɤ ɪɟɡɭɥɶɬɚɬɵɩɨɢɫɤɚɜɮɚɣɥɟɤɚɬɚɥɨɝɟɢɥɢɩɪɨɟɤɬɟ
ɨɬɨɛɪɚɠɚɟɬ
Ɋɢɫɭɧɨɤ± Ɋɟɡɭɥɶɬɚɬɵɩɨɢɫɤɚ
ɉɚɧɟɥɶ ȼɵɜɨɞ ɩɪɢɥɨɠɟɧɢɹ ɪɢɫɭɧɨɤ ɩɨɤɚɡɵɜɚɟɬ ɫɬɚɬɭɫ
ɩɪɨɝɪɚɦɦɵɩɪɢɟɟ ɜɵɩɨɥɧɟɧɢɢɢɨɬɥɚɞɨɱɧɭɸ ɢɧɮɨɪɦɚɰɢɸ.
12