{"id":286702,"date":"2017-05-22T20:20:03","date_gmt":"2017-05-22T16:20:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=286702"},"modified":"-0001-11-30T00:00:00","modified_gmt":"2017-05-22T16:20:03","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=286702","title":{"rendered":"\u0421\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f QComboBox"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/251\/8f9\/a9a\/2518f9a9a8644242b9d9fed43f4fe7e0.png\"\/><\/p>\n<p>  \u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u0430\u043c\u0438 \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 <em>QComboBox<\/em> \u0432 Qt. \u0412 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441\u0430 \u0438\u0437 \u0411\u0414, \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u043a\u043e\u0434\u0430.<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h1>\u0421\u043f\u043e\u0441\u043e\u0431 \u21161. \u041f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0440\u0443\u0447\u043d\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438<\/h1>\n<p>  <\/p>\n<p>\u0412\u0441\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 Qt \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a\u0430\u043c\u0438 \u043e\u0442 <em>QAbstractItemModel<\/em>. \u041b\u0438\u0447\u043d\u043e \u0432 \u043c\u043e\u0435\u0439 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u043b\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 SQL \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u042d\u0442\u043e \u0431\u044b\u043b\u0438 \u043f\u043e\u043b, \u0441\u0442\u0440\u0430\u043d\u0430, \u043d\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0438 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u043f\u0438\u0441\u043a\u0438, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u043f\u0443\u043d\u043a\u0442. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u043c\u043e\u0434\u0435\u043b\u0438, \u0443 \u043c\u0435\u043d\u044f \u0432\u0441\u0435\u0433\u0434\u0430 \u0431\u044b\u043b\u043e \u0434\u0432\u0435 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0438:  <\/p>\n<ol>\n<li>\u041a\u0430\u043a \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043f\u0443\u043d\u043a\u0442\u043e\u0432 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e?<\/li>\n<li>\u041a\u0430\u043a \u0441\u0432\u044f\u0437\u0430\u0442\u044c \u0447\u0438\u0442\u0430\u0435\u043c\u044b\u0435 \u043f\u0443\u043d\u043a\u0442\u044b \u0441 \u043a\u043b\u044e\u0447\u0430\u043c\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0434\u043e \u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u0411\u0414?<\/li>\n<\/ol>\n<p>  \u041d\u0430 \u0432\u0441\u044f\u043a\u0438\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u043f\u043e\u044f\u0441\u043d\u044e \u0440\u0430\u0437\u043d\u0438\u0446\u0443, \u0435\u0441\u043b\u0438 \u043a\u043e\u043c\u0443 \u043d\u0435 \u043f\u043e\u043d\u044f\u0442\u043d\u043e. \u041f\u0435\u0440\u0432\u044b\u0439 \u043f\u0443\u043d\u043a\u0442 \u044d\u0442\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0435 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u043f\u0443\u043d\u043a\u0442\u0430. \u0412 \u043c\u043e\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441 \u0434\u043b\u044f \u0432\u044b\u0431\u043e\u0440\u0430 \u043d\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439. \u0422\u0430\u043c \u0431\u0443\u0434\u0443\u0442 \u0441\u043b\u043e\u0432\u0430 \u0442\u0438\u043f\u0430 \u00abRussian\u00bb, \u00abBelgian\u00bb, \u00abNorwegian\u00bb \u0438 \u0442.\u043f. \u0422\u043e \u0447\u0442\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0443\u0432\u0438\u0434\u0438\u0442 \u043d\u0430 \u044d\u043a\u0440\u0430\u043d\u0435. \u0412\u0442\u043e\u0440\u043e\u0435 \u044d\u0442\u043e \u0442\u043e \u0447\u0442\u043e \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445. \u0423\u0441\u043b\u043e\u0432\u043d\u043e \u00ab\u0441\u043b\u0443\u0436\u0435\u0431\u043d\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u00bb. \u0412 \u043c\u043e\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432 \u0431\u0430\u0437\u0443 \u043f\u0438\u0448\u0435\u0442\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0442\u0438\u043f\u0430: \u00abrussian\u00bb, \u00abbelgian\u00bb, \u00abnorwegian\u00bb. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u0435\u043d\u044f\u0442\u044c \u0432\u0438\u0434\u0438\u043c\u044b\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043f\u0443\u043d\u043a\u0442\u043e\u0432 \u0431\u0435\u0437 \u043b\u0438\u0448\u043d\u0438\u0445 \u0445\u043b\u043e\u043f\u043e\u0442. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0430\u043b\u0438 \u0432\u0430\u043c \u0437\u0430\u0434\u0430\u043d\u0438\u0435 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u0448\u0438\u0440\u0438\u043d\u0443 \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441\u0430, \u0437\u0430 \u0441\u0447\u0451\u0442 \u0441\u043e\u043a\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0439 \u043d\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439. \u0412\u0430\u043c \u043d\u0430\u0434\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0435 \u00abRussian\u00bb, \u0430 \u00abRus.\u00bb. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0432\u044b \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u043c\u0435\u043d\u044f\u0435\u0442\u0435 \u0442\u0435\u043a\u0441\u0442 \u0432\u044b\u0432\u043e\u0434\u0438\u043c\u044b\u0439 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0438 \u0437\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0435 \u0437\u0430\u0434\u0430\u0447\u0443. \u0415\u0441\u043b\u0438 \u0436\u0435 \u0432 \u0431\u0430\u0437\u0443 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u044f\u043c\u043e \u0442\u043e \u0447\u0442\u043e \u0432\u0438\u0434\u043d\u043e \u0432 \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441\u0435. \u0418\u0437\u043c\u0435\u043d\u043d\u0438\u0435 \u00abRussian\u00bb -&gt; \u00abRus.\u00bb \u0437\u0430\u0441\u0442\u0430\u0432\u0438\u0442 \u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0434\u0443\u0440\u044b \u0434\u043b\u044f \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u0421 \u0446\u0435\u043b\u044c\u044e \u043f\u0435\u0440\u0435\u0432\u043e\u0434\u0430 \u0441\u0442\u0430\u0440\u044b\u0445 \u0438\u043c\u0435\u043d \u0432 \u043d\u043e\u0432\u044b\u0435. \u0427\u0442\u043e \u0431\u044b \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u043b\u0438\u0441\u044c \u0443\u0436\u0435 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u043d\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0432 \u0431\u0430\u0437\u0430\u0445 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439. \u041a\u043e\u0440\u043e\u0447\u0435 \u0434\u0432\u0430 \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f(\u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0435, \u0441\u043b\u0443\u0436\u0435\u0431\u043d\u043e\u0435) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0443\u043d\u043a\u0442\u0430. \u042d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u0430\u044f \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u043e\u0433\u043e \u043a\u043e\u0434\u0430.  <\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0437\u0430\u043c\u044b\u0441\u043b\u0430. \u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u043d\u0430\u0434\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043a\u0430\u043a\u0438\u0435 \u0438\u0437 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 <em>QAbstractItemModel<\/em>, \u0432\u044b <strong>\u043e\u0431\u044f\u0437\u0430\u043d\u044b<\/strong> \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0443 \u0441\u0435\u0431\u044f:  <\/p>\n<ul>\n<li>QModelIndex QAbstractItemModel::index(int row, int column, const QModelIndex &#038; parent = QModelIndex()) const<\/li>\n<li>QModelIndex QAbstractItemModel::parent(const QModelIndex &#038; index) const<\/li>\n<li>int QAbstractItemModel::columnCount(const QModelIndex &#038; parent = QModelIndex()) const<\/li>\n<li><strong>int QAbstractItemModel::rowCount(const QModelIndex &#038; parent = QModelIndex()) const<\/strong><\/li>\n<li><strong>QVariant QAbstractItemModel::data(const QModelIndex &#038; index, int role = Qt::DisplayRole) const<\/strong><\/li>\n<\/ul>\n<p>  \u0422.\u0435. \u0437\u0434\u0435\u0441\u044c \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u044b \u00ab\u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435\u00bb(\u00abpure virtual\u00bb) \u043c\u0435\u0442\u043e\u0434\u044b. \u041a\u0430\u0437\u0430\u043b\u043e\u0441\u044c \u0431\u044b \u0441\u0430\u043c\u044b\u043c \u0441\u0442\u0440\u0430\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c <em>columnCount()<\/em>. \u0422.\u043a. \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e \u0447\u0442\u043e \u043a\u043e\u043b\u043e\u043d\u043a\u0430 \u043e\u0434\u043d\u0430. \u041f\u043e\u0442\u043e\u043c <em>index()<\/em> \u0438 <em>parent()<\/em> \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u043a\u0430\u043a \u0442\u043e \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e, \u043d\u0430 \u0444\u043e\u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u043b\u0438\u043d\u0435\u0439\u043d\u043e\u0439 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0434\u0430\u043d\u043d\u044b\u0445(\u0441\u043f\u0438\u0441\u043e\u043a). \u041e\u043d\u0438 \u043d\u0443\u0436\u043d\u044b \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u043b\u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0438\u044f \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0442\u0438\u043f\u0430 \u0434\u0435\u0440\u0435\u0432\u044c\u0435\u0432 \u0434\u043b\u044f <em>QTreeView<\/em>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0447\u0442\u043e \u0431\u044b \u043d\u0435 \u0432\u044b\u0434\u0443\u043c\u044b\u0432\u0430\u0442\u044c \u0441\u0435\u0431\u0435 \u043b\u0438\u0448\u043d\u044e\u044e \u0440\u0430\u0431\u043e\u0442\u0443, \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u044c \u043a\u043b\u0430\u0441\u0441 \u043c\u043e\u0434\u0435\u043b\u0438 \u043e\u0442 <em>QAbstractListModel<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0442\u043e\u0436\u0435 \u0433\u043e\u0434\u0435\u043d \u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435. \u0418 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u0432\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445(\u00abpure virtual\u00bb) \u043c\u0435\u0442\u043e\u0434\u0430 \u0438\u0437 \u0441\u043f\u0438\u0441\u043a\u0430.  <\/p>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0434\u043b\u044f \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441\u0430 \u0432\u044b\u0431\u043e\u0440\u0430 \u043d\u0430\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438. \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0438:  <\/p>\n<pre><code class=\"cpp\">\/\/ nationalitymodel.h \/\/ #pragma once #include &lt;QAbstractListModel&gt;  class NationalityModel : public QAbstractListModel { \tQ_OBJECT  \ttypedef QPair&lt;QVariant, QVariant&gt; DataPair; \tQList&lt; DataPair &gt; m_content;  public: \texplicit NationalityModel( QObject *parent = 0 ); \tvirtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; \tvirtual int rowCount( const QModelIndex & parent = QModelIndex() ) const; };  \/\/ nationalitymodel.cpp #include &quot;nationalitymodel.h&quot;  NationalityModel::NationalityModel(QObject *parent) : \tQAbstractListModel(parent) { \tm_content &lt;&lt; qMakePair( DataPair::first_type(), DataPair::second_type( &quot;&quot; ) ) \t\t\t&lt;&lt; qMakePair( DataPair::first_type( &quot;Russian&quot; ), DataPair::second_type( &quot;russian&quot; ) ) \t\t\t&lt;&lt; qMakePair( DataPair::first_type( &quot;Belgian&quot; ), DataPair::second_type( &quot;belgian&quot; ) ) \t\t\t&lt;&lt; qMakePair( DataPair::first_type( &quot;Norwegian&quot; ), DataPair::second_type( &quot;norwegian&quot; ) ) \t\t\t&lt;&lt; qMakePair( DataPair::first_type( &quot;American&quot; ), DataPair::second_type( &quot;american&quot; ) ) \t\t\t&lt;&lt; qMakePair( DataPair::first_type( &quot;German&quot; ), DataPair::second_type( &quot;german&quot; ) ); }  QVariant NationalityModel::data( const QModelIndex &index, int role ) const { \tconst DataPair& data = m_content.at( index.row() ); \tQVariant value;  \tswitch ( role ) \t{ \t\tcase Qt::DisplayRole: \t\t{ \t\t\tvalue = data.first; \t\t} \t\tbreak;  \t\tcase Qt::UserRole: \t\t{ \t\t\tvalue = data.second; \t\t} \t\tbreak;  \t\tdefault: \t\t\tbreak; \t}  \treturn value; }  int NationalityModel::rowCount(const QModelIndex &\/*parent*\/) const { \treturn m_content.count(); }  \/\/ addressbookmainwindow.cpp. \u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u0444\u043e\u0440\u043c\u044b, \u0433\u0434\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u044c ( AddressBookMainWindow::AddressBookMainWindow() ) ui-&gt;nationalityCombo-&gt;setModel( new NationalityModel( this ) ); <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/134\/8e3\/fbc\/1348e3fbcae944a7a054e8d5b8b8ce4d.png\"\/>  <\/p>\n<p>\u0412\u0441\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0443\u043d\u043a\u0442\u043e\u0432 \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441\u0430, \u043f\u0440\u043e\u0441\u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0442\u044c\u0441\u044f \u0432 <em>QList&lt; DataPair &#038;gt m_content;<\/em>. \u0418 \u043f\u043e\u0442\u043e\u043c \u0432\u044b\u0434\u0430\u044e\u0442\u0441\u044f \u043f\u0440\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0438 \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441\u0430 \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 <em>NationalityModel::data()<\/em>. \u041d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c \u0432\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c. \u041d\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442 \u044f\u0432\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 \u044d\u0442\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e \u0432 \u0441\u0432\u043e\u0451\u043c \u043a\u043e\u0434\u0435. \u0410 \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u043a \u0434\u0430\u043d\u043d\u043e\u0439 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043a\u043e\u0433\u0434\u0430 \u0435\u043c\u0443 \u043d\u0430\u0434\u043e! \u0412\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430, \u0447\u0442\u043e \u0431\u044b \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u043e\u0442\u0434\u0430\u0432\u0430\u043b\u0430 \u044d\u0442\u0438 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u0437\u0430\u043f\u0440\u043e\u0441\u0443.<\/p>\n<p>  <em>NationalityModel::data()<\/em> \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u0434\u0432\u0443\u043c\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438. \u041a\u0430\u043a \u0442\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u043e\u0442\u0438\u043f <em>QAbstractItemModel::data()<\/em>:  <\/p>\n<ul>\n<li><strong>const QModelIndex &#038;index<\/strong>. \u041e\u0431\u044a\u0435\u043a\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438, \u043a\u043e\u043b\u043e\u043d\u043a\u0438 \u0438 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 <em>QModelIndex<\/em>. \u0422.\u0435. QComboBox \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442 \u043c\u0435\u0441\u0442\u043e(\u043f\u043e\u0437\u0438\u0446\u0438\u044e) \u043f\u0443\u043d\u043a\u0442\u0430, \u0434\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0430\u043a\u0442\u0443\u0430\u043b\u0435\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u043e\u043c\u0435\u0440 \u0441\u0442\u0440\u043e\u043a\u0438. \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432\u043d\u0443\u0442\u0440\u0438 <em>&#038;index<\/em> \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u0438 \u0441 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438, \u0442\u0438\u043f\u0430 <em>QTreeView<\/em> \u0438 <em>QTableView<\/em>. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0448\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u043f\u0430\u0440\u0443, \u00ab\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0435\u00bb \u0438 \u00ab\u0441\u043b\u0443\u0436\u0435\u0431\u043d\u043e\u0435\u00bb \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f <em>(DataPair)<\/em> \u0442\u043e\u043b\u044c\u043a\u043e \u0434\u043b\u044f \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0425\u0440\u0430\u043d\u044f\u0449\u0438\u0435\u0441\u044f \u0432 \u0441\u043f\u0438\u0441\u043a\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 <em>(m_content).<\/em> <\/li>\n<li><strong>int role<\/strong>. \u0412 \u044d\u0442\u043e\u043c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0435 <em>QComboBox<\/em> \u0441\u043e\u043e\u0431\u0449\u0430\u0435\u0442, \u043a\u0430\u043a\u043e\u0433\u043e \u0440\u043e\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0443\u0436\u043d\u044b(\u043a\u0430\u043a\u0430\u044f \u0440\u043e\u043b\u044c). \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u00ab\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0435\u00bb \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u044d\u0442\u043e <em>Qt::DisplayRole<\/em>, \u0430 \u00ab\u0441\u043b\u0443\u0436\u0435\u0431\u043d\u043e\u0435\u00bb <em>Qt::UserRole<\/em>. <\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0417\u0430 \u043e\u0434\u0438\u043d \u0432\u044b\u0437\u043e\u0432 <em>NationalityModel::data()<\/em> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0442\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0434\u043d\u043e\u0439 \u0440\u043e\u043b\u0438 \u0434\u043b\u044f \u043e\u0434\u043d\u043e\u0439, \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438 \u0432 \u0441\u043f\u0438\u0441\u043a\u0435.  <\/p>\n<p>  <\/p>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0441\u044f \u043a <em>enum ItemDataRole<\/em>, \u0433\u0434\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u044b <em>Qt::DisplayRole, Qt::UserRole<\/em>. \u0421\u0442\u0430\u043d\u0435\u0442 \u043f\u043e\u043d\u044f\u0442\u043d\u043e \u0434\u043b\u044f \u0447\u0435\u0433\u043e \u0435\u0449\u0451 \u043c\u043e\u0436\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0430\u043a\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u043e\u043c\u0435\u043d\u044f\u0442\u044c \u0448\u0440\u0438\u0444\u0442 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043f\u0443\u043d\u043a\u0442\u043e\u0432 <em>(Qt::FontRole)<\/em>. \u0412\u044b\u0440\u043e\u0432\u043d\u044f\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u043f\u0443\u043d\u043a\u0442\u0430 \u043c\u0435\u043d\u044e, \u043a\u0430\u043a \u0442\u043e \u043f\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u043c\u0443. \u0418\u043b\u0438 \u0437\u0430\u0434\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0432\u0441\u043f\u043b\u044b\u0432\u0430\u044e\u0449\u0435\u0439 \u043f\u043e\u0434\u0441\u043a\u0430\u0437\u043a\u0438. \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0432 \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u044b\u0439 enum. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u044b \u043d\u0430\u0439\u0434\u0451\u0442\u0435 \u0442\u0430\u043c \u0442\u043e \u0447\u0442\u043e \u0438\u0441\u043a\u0430\u043b\u0438 \u0443\u0436\u0435 \u0434\u0430\u0432\u043d\u043e.<\/p>\n<h2>\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043c\u0435\u0440\u0430<\/h2>\n<p>  <\/p>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e \u0438\u0437\u0443\u0447\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0432 \u0440\u0430\u0431\u043e\u0442\u0435. \u0414\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 \u0431\u044b\u043b \u0441\u043e\u0437\u0434\u0430\u043d\u0430 <a href=\"https:\/\/github.com\/stanislav888\/AddressBook\">\u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0430\u0434\u0440\u0435\u0441\u043d\u043e\u0439 \u043a\u043d\u0438\u0433\u0438.<\/a>   <\/p>\n<p>  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u043a\u0430\u043a \u0441\u043a\u0430\u0447\u0430\u0442\u044c \u043a\u043e\u0434 \u0441 github.com<\/b><\/p>\n<div class=\"spoiler_text\"> \u041d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430:   <\/p>\n<ol>\n<li>\u0421\u043a\u0430\u0447\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442 <em>\u00abgit clone <a href=\"https:\/\/github.com\/stanislav888\/AddressBook.git\">github.com\/stanislav888\/AddressBook.git<\/a>\u00bb<\/em><\/li>\n<li>\u041c\u0435\u043d\u044f\u0435\u0442\u0435 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 <em>\u00abcd AddressBook\u00bb<\/em><\/li>\n<li>\u0418\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0439\u0442\u0435 \u043f\u043e\u0434\u043c\u043e\u0434\u0443\u043b\u044c <em>\u00abgit submodule init\u00bb<\/em><\/li>\n<li>\u041f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0435 \u043a\u043e\u0434 \u043f\u043e\u0434\u043c\u043e\u0434\u0443\u043b\u044f \u0432 \u043f\u0440\u043e\u0435\u043a\u0442 <em>\u00abgit submodule update\u00bb<\/em><\/li>\n<li>\u041e\u0442\u043a\u0440\u044b\u0432\u0430\u0435\u0442\u0435 \u0438 \u0441\u043e\u0431\u0438\u0440\u0430\u0435\u0442\u0435 \u043f\u0440\u043e\u0435\u043a\u0442<\/li>\n<li>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0443<\/li>\n<li>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u0445\u043e\u0440\u043e\u0448\u043e, \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u043a\u043d\u043e \u0432\u044b\u0431\u043e\u0440\u0430\\\u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0431\u0430\u0437\u044b \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0447\u0442\u043e \u0437\u0430 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430. \u0414\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0435\u0441\u0442\u044c \u043a\u043d\u043e\u043f\u043e\u0447\u043a\u0430 \u00abFill test data\u00bb<\/li>\n<\/ol>\n<p>  \u0414\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u043d\u0430\u0434\u043e \u0438\u043c\u0435\u0442\u044c QtCreator c Qt \u043d\u0435 \u043d\u0438\u0436\u0435 5.0. \u041b\u0438\u0447\u043d\u043e \u044f \u0441\u043e\u0431\u0438\u0440\u0430\u043b \u043f\u0440\u043e\u0435\u043a\u0442 \u0441 Qt 5.5.0 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0442\u043e\u0440\u043e\u043c gcc 5.3.1. \u0425\u043e\u0442\u044f \u043f\u0440\u043e\u0435\u043a\u0442 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0438 \u0434\u0430\u0436\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 Qt 4.8.1. \u0414\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u0411\u0414 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u0435 \u0434\u043b\u044f Firefox <a href=\"https:\/\/addons.mozilla.org\/en-US\/firefox\/addon\/sqlite-manager\/\">SQLite Manager<\/a>.  <\/div>\n<\/div>\n<h1>\u0421\u043f\u043e\u0441\u043e\u0431 \u21162. \u0411\u044b\u0441\u0442\u0440\u043e\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u0437 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432 SQL \u0411\u0414<\/h1>\n<p>  <\/p>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0436\u0435 \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431 \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439. \u042d\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0445 \u0432 \u0431\u0430\u0437\u0435, \u0432 \u0432\u0438\u0434\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446. \u0418 \u043f\u043e\u0434\u0433\u0440\u0443\u0436\u0430\u0442\u044c \u0432 \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441\u044b \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430\u0445 \u0444\u043e\u0440\u043c. \u0418 \u0431\u044b\u043b\u043e \u0431\u044b \u0438\u0434\u0435\u0430\u043b\u044c\u043d\u043e \u0438\u043c\u0435\u0442\u044c \u043a\u0430\u043a\u043e\u0435-\u0442\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435. \u0412\u043c\u0435\u0441\u0442\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0445 \u043a\u043b\u0430\u0441\u0441\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f.  <\/p>\n<p>  <\/p>\n<p>\u0414\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f <em>QSqlQueryModel<\/em>. \u042d\u0442\u043e \u043f\u043e\u0445\u043e\u0436\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c. \u041e\u043d\u0430 \u0442\u043e\u0436\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u043d\u0438\u043a <em>QAbstractItemModel<\/em>, \u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430 <em>QSqlQuery<\/em> \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 <em>QTableView.<\/em> \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u043d\u0430\u0448\u0430 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u0438\u0441\u043f\u043e\u0441\u043e\u0431\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441. \u0427\u0442\u043e \u0431\u044b \u043e\u043d \u0434\u0430\u0432\u0430\u043b \u0434\u0430\u043d\u043d\u044b\u0435 \u0442\u0430\u043a \u0436\u0435 \u043a\u0430\u043a \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435.<\/p>\n<p>  \u0412\u044b \u0443\u0434\u0438\u0432\u0438\u0442\u0435\u0441\u044c, \u043d\u043e \u043a\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u043c.  <\/p>\n<pre><code class=\"cpp\">\/\/ addressdialog.h \/\/\/ #pragma once #include &lt;QSqlQueryModel&gt;  class BaseComboModel : public QSqlQueryModel { \tQ_OBJECT  \tQVariant dataFromParent(QModelIndex index, int column) const;  public: \texplicit BaseComboModel( const QString &columns, const QString &queryTail, QObject *parent = 0 ); \tvirtual QVariant data(const QModelIndex &item, int role = Qt::DisplayRole) const; \tvirtual int rowCount(const QModelIndex &parent) const; };  \/\/ basecombomodel.cpp #include &quot;basecombomodel.h&quot; #include &lt;QSqlQuery&gt;  namespace { \tenum Columns \/\/ Depends with 'query.prepare( QString( &quot;SELECT ... ' \t{ \t\tId, \t\tData, \t}; }  BaseComboModel::BaseComboModel( const QString& visualColumn, const QString& queryTail, QObject *parent ) : \tQSqlQueryModel( parent ) { \tQSqlQuery query; \tquery.prepare( QString( &quot;SELECT %1.id, %2 FROM %3&quot; ).arg( queryTail.split( ' ' ).first() ).arg( visualColumn ).arg( queryTail ) ); \t\/\/ I.e. query.prepare( &quot;SELECT country.id, countryname || ' - ' || countrycode  FROM country&quot; ); \tquery.exec(); \tQSqlQueryModel::setQuery( query ); }  QVariant BaseComboModel::dataFromParent( QModelIndex index, int column ) const { \treturn QSqlQueryModel::data( QSqlQueryModel::index( index.row() - 1 \/\/ &quot;- 1&quot; because make first row empty \t\t\t\t\t\t\t\t\t\t\t\t\t\t, column ) ); }  int BaseComboModel::rowCount(const QModelIndex &parent) const { \treturn QSqlQueryModel::rowCount( parent ) + 1; \/\/ Add info about first empty row }  QVariant BaseComboModel::data(const QModelIndex & item, int role \/* = Qt::DisplayRole *\/) const { \tQVariant result;  \tif( item.row() == 0 ) \/\/ Make first row empty \t{ \t\tswitch( role ) \t\t{ \t\t\tcase Qt::UserRole: \t\t\t\tresult = 0; \t\t\t\tbreak; \t\t\tcase Qt::DisplayRole: \t\t\t\tresult = &quot;(please select)&quot;; \t\t\t\tbreak; \t\t\tdefault: \t\t\t\tbreak; \t\t} \t} \telse \t{ \t\tswitch( role ) \t\t{ \t\t\tcase Qt::UserRole: \t\t\t\tresult = dataFromParent( item, Id ); \t\t\t\tbreak; \t\t\tcase Qt::DisplayRole: \t\t\t\tresult = dataFromParent( item, Data ); \t\t\t\tbreak; \t\t\tdefault: \t\t\t\tbreak; \t\t} \t}  \treturn result; }  \/\/ \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0432 \u0444\u043e\u0440\u043c\u0435(addressdialog.ui) \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a ui-&gt;countryCombo-&gt;setModel(  new BaseComboModel( &quot;countryname || ' - ' || countrycode&quot;, &quot;country&quot;,  this ) );  <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/3ea\/557\/1ef\/3ea5571efda740ed9769bf201b60b91a.png\"\/>  <\/p>\n<p>\u0412 \u0434\u0430\u043d\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u0432\u0441\u044e \u0440\u0430\u0431\u043e\u0442\u0443 \u0434\u0435\u043b\u0430\u0435\u0442 <em>QSqlQueryModel<\/em>. \u041d\u0430\u0434\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u043b\u043e\u0433\u0438\u043a\u0443 <em>QSqlQueryModel::data().<\/em> \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u044c\u0442\u0435, \u0447\u0442\u043e \u0432 \u043c\u043e\u0434\u0435\u043b\u044c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442\u0441\u044f SQL \u0437\u0430\u043f\u0440\u043e\u0441 <em>\u00abSELECT country.id, countryname || &#8216; \u2014 &#8216; || countrycode FROM country\u00bb<\/em>.<\/p>\n<p> \u041a\u043e\u043d\u0435\u0447\u043d\u043e \u0432 \u043a\u043e\u0434\u0435 \u043f\u0440\u043e\u0435\u043a\u0442\u0430 \u044d\u0442\u043e \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0431\u043e\u043b\u0435\u0435 \u0437\u0430\u043c\u044b\u0441\u043b\u043e\u0432\u0430\u0442\u043e. \u041d\u043e \u0435\u0441\u043b\u0438 \u043e\u0442\u043b\u0430\u0434\u0438\u0442\u044c \u0442\u0430\u043c \u0431\u0443\u0434\u0435\u0442 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u0430\u043a\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0430. \u0417\u0430\u043f\u0440\u043e\u0441 \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0434\u0432\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430. \u041f\u0435\u0440\u0432\u0438\u0447\u043d\u044b\u0439 \u043a\u043b\u044e\u0447<em>(\u00abid\u00bb).<\/em> \u0418 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u043d\u0438\u0435, \u0432\u0438\u0434\u0438\u043c\u043e\u0435 \u043d\u0430 \u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u0435. \u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0432\u0441\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0432 <em>Qt::DisplayRole<\/em> \u0443 <em>QSqlQueryModel<\/em>. \u0422\u043e \u0431\u0435\u0437 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f <em>QSqlQueryModel<\/em>, \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441\u0430, \u0432\u044b\u0434\u0430\u0441\u0442 \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u00abid\u00bb. \u0410 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u0438\u0434\u043d\u043e. \u0422.\u043a. \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441 \u043d\u0438\u043a\u0430\u043a \u043d\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0432\u0442\u043e\u0440\u043e\u0439 \u0441\u0442\u043e\u043b\u0431\u0435\u0446 \u043c\u043e\u0434\u0435\u043b\u0438(\u0437\u0430\u043f\u0440\u043e\u0441\u0430). \u0412\u044b \u044d\u0442\u043e \u0443\u0432\u0438\u0434\u0438\u0442\u0435, \u0435\u0441\u043b\u0438 \u0437\u0430\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u0435 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <em>BaseComboModel::data().<\/em><br \/>  \u0414\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e \u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0440\u0430\u043d, \u043a\u0430\u043a \u043d\u0430 \u0441\u043a\u0440\u0438\u043d\u0448\u043e\u0442\u0435, <em>BaseComboModel::data()<\/em>:  <\/p>\n<ul>\n<li>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0437\u0430\u043f\u0440\u043e\u0448\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430<em>(\u00abid\u00bb)<\/em> \u043a\u0430\u043a <em>Qt::UserRole<\/em> \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430<\/li>\n<li>\u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432\u0442\u043e\u0440\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430<em>(\u00abcountryname || &#8216; \u2014 &#8216; || countrycode\u00bb)<\/em> \u043a\u0430\u043a <em>Qt::DisplayRole<\/em> \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430<\/li>\n<li>\u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 &quot;(please select)&quot; \u0432 \u0441\u0430\u043c\u043e\u043c \u043d\u0430\u0447\u0430\u043b\u0435. \u0417\u0430 \u0441\u0447\u0451\u0442 \u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u043d\u043e\u043c\u0435\u0440\u043e\u0432 \u043f\u0440\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0442 <em>QSqlQueryModel<\/em>. \u0422.\u0435. \u043a \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430\u043c SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0430\u043c\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 \u0441\u0442\u0440\u043e\u043a\u0443<\/li>\n<\/ul>\n<p>  <\/p>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u043b\u0435\u0433\u043a\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043b\u044f <em>QComboBox-\u0430<\/em> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <em>BaseComboModel.<\/em> \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u0432\u0430\u0441 \u0435\u0441\u0442\u044c SQL \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u043c\u0435\u0441\u044f\u0446\u0435\u0432 \u0432 \u0433\u043e\u0434\u0443(\u00abmonths\u00bb). \u0413\u0434\u0435 \u0434\u0432\u0430 \u0441\u0442\u043e\u043b\u0431\u0446\u0430, \u00abid\u00bb \u0438 \u00abmonthname\u00bb. \u0412\u0430\u043c \u043c\u043e\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u044c \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441 \u0432\u044b\u0431\u043e\u0440\u0430 \u043c\u0435\u0441\u044f\u0446\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<br \/>  <strong>ui-&gt;monthsCombo-&gt;setModel( new BaseComboModel( \u00abmonthname\u00bb, \u00abmonths\u00bb, this ) );<\/strong><br \/>  \u041f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u00abid\u00bb \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u044f\u0446\u0430 <em>ui-&gt;monthsCombo-&gt;itemData( ui-&gt;monthsCombo-&gt;currentIndex(), Qt::UserRole );<\/em>. \u041f\u043e\u043b\u0443\u0447\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0432\u0438\u0434\u0438\u043c\u043e\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e <em>ui-&gt;monthsCombo-&gt;currentText();<\/em>. \u042d\u0442\u043e\u0442 \u043a\u043e\u0434 \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u0435\u0435 \u0432\u0441\u0435\u0445 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432. \u0411\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0432 \u0434\u0430\u043d\u043d\u043e\u0439 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0438 \u043f\u0438\u0448\u0443\u0442, \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u043f\u0440\u043e\u0441 \u043a \u0431\u0430\u0437\u0435 <em>(QSqlQuery)<\/em>. \u0410 \u043f\u043e\u0442\u043e\u043c, \u0432 \u0446\u0438\u043a\u043b\u0435, \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441, \u0447\u0435\u0440\u0435\u0437 <em>QComboBox::addItem()<\/em>. \u042d\u0442\u043e \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u0440\u0430\u0431\u043e\u0447\u0435\u0435, \u043d\u043e \u043d\u0435 \u0441\u0430\u043c\u043e\u0435 \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435.  <\/p>\n<h2>\u041f\u0440\u0430\u043a\u0442\u0438\u043a\u0430<\/h2>\n<p>  <\/p>\n<p>\u041f\u043e\u0434\u043e\u0437\u0440\u0435\u0432\u0430\u044e, \u043d\u0435 \u0432\u0441\u0435 \u043f\u043e\u043d\u044f\u043b\u0438 \u043a\u0430\u043a \u0442\u0443\u0442 \u0432\u0441\u0451 \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0443\u0436\u0435\u043d \u043e\u0447\u0435\u043d\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043e\u043f\u044b\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u0432\u043e\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0447\u0442\u043e \u0431\u044b \u0432\u0430\u0448\u0435 \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u0441\u0442\u0430\u0442\u044c\u044e \u043d\u0435 \u043f\u0440\u043e\u043f\u0430\u043b\u043e \u0434\u0430\u0440\u043e\u043c. \u0414\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435. \u0427\u0442\u043e \u0431\u044b \u043f\u043e\u0442\u043e\u043c, \u0441\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0435\u043c \u043f\u043e\u043d\u044f\u0442\u044c \u0435\u0433\u043e.<\/p>\n<p>  \u0414\u0432\u0430 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430 \u043a\u0430\u043a \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c:  <\/p>\n<ol>\n<li>\u042d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u044b \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043c\u043e\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u2014 \u0430\u0434\u0440\u0435\u0441\u043d\u043e\u0439 \u043a\u043d\u0438\u0433\u0438, \u0443\u043f\u043e\u043c\u044f\u043d\u0443\u0442\u043e\u0439 \u0432\u044b\u0448\u0435. \u0417\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u043a \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <em>BaseComboModel<\/em> \u0443\u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0443\u044e\u0442 \u0432 \u043f\u0440\u043e\u0435\u043a\u0442\u0435. \u041f\u0440\u0438\u043c\u0435\u0440\u044b \u043d\u0438\u0436\u0435, \u0431\u0443\u0434\u0443\u0442 \u043d\u0430 \u0435\u0451 \u043e\u0441\u043d\u043e\u0432\u0435<\/li>\n<li>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043b\u044e\u0431\u043e\u0435 \u0434\u0440\u0443\u0433\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0435 \u0441 SQL \u0411\u0414. \u042d\u0442\u043e \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c SQLite. \u041f\u043e\u0434\u043e\u0439\u0434\u0451\u0442 \u043b\u044e\u0431\u0430\u044f \u0431\u0430\u0437\u0430! \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043a\u043e\u0434 \u0438\u0437 \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430 \u0432\u044b\u0448\u0435, \u0432 \u0444\u0430\u0439\u043b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043b\u044e\u0431\u043e\u0439 \u0444\u043e\u0440\u043c\u044b. <br \/>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b, \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043e\u0447\u043d\u044b\u0439 \u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u043b\u044f <em>BaseComboModel<\/em>. \u0411\u0443\u0434\u0435\u043c \u0441\u0447\u0438\u0442\u0430\u0442\u044c \u0447\u0442\u043e \u043f\u043e\u043a\u0430 \u043d\u0430\u043c \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043b\u0435\u043d\u044c. \u0412\u0430\u043c \u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043f\u0440\u0438\u0434\u0451\u0442\u0441\u044f \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043f\u043e\u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f \u0441 \u043e\u0448\u0438\u0431\u043a\u0430\u043c\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438. \u041d\u043e \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u043c\u0438. \u0412 \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445, \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u0431\u0440\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441\u0430. \u041e\u0431\u044f\u0437\u0430\u043d \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u043e\u043b\u0431\u0435\u0446 <em>\u00abid\u00bb<\/em><\/li>\n<\/ol>\n<p>  \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0430 <em>BaseComboModel( const QString &#038;columns, const QString &#038;queryTail, QObject *parent = 0 )<\/em>:  <\/p>\n<ul>\n<li><strong>const QString &#038;columns<\/strong>. \u0424\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u043e\u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0433\u043e \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u044f \u043f\u0443\u043d\u043a\u0442\u0430 \u0434\u043b\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0432\u044b\u0448\u0435 <em>\u00abcountryname || &#8216; \u2014 &#8216; || countrycode\u00bb<\/em> \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u044f \u0434\u0432\u0443\u0445 \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u0434\u0435\u0444\u0438\u0441. \u041e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u0438 &quot;||&quot; \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u0439 \u0434\u043b\u044f SQLite. \u041c\u043e\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043f\u044f\u0442\u0443\u044e. \u041d\u043e \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c\u0441\u044f \u0431\u0443\u0434\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u0435\u0440\u0432\u044b\u0439<\/li>\n<li><strong>const QString &#038;queryTail<\/strong>. \u00ab\u0425\u0432\u043e\u0441\u0442\u00bb \u0437\u0430\u043f\u0440\u043e\u0441\u0430. \u0421\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 SQL \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043f\u043e\u0441\u043b\u0435 <em>\u00abFROM\u00bb<\/em>. \u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0432 \u044d\u0442\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0438\u043c\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0438\u0437 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0431\u0443\u0434\u0443\u0442 \u0431\u0440\u0430\u0442\u044c\u0441\u044f \u0434\u0430\u043d\u043d\u044b\u0435. \u041d\u043e \u043f\u043e\u0442\u043e\u043c \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0443\u0441\u043b\u043e\u0432\u0438\u0435 <em>\u00abWHERE\u00bb<\/em> \u0438 \u0435\u0449\u0451 \u043c\u043d\u043e\u0433\u043e \u0432\u0441\u0435\u0433\u043e<\/li>\n<\/ul>\n<p>  <\/p>\n<p> \u0414\u0430\u043b\u0435\u0435, \u043d\u0430\u0434\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0430 \u0444\u043e\u0440\u043c\u0443 <em>QComboBox<\/em> \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0432\u044b \u0431\u0443\u0434\u0435\u0442\u0435 \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0412 \u043c\u043e\u0451\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 <em>addressbookmainwindow.ui<\/em>. \u0418\u043c\u044f \u043d\u043e\u0432\u043e\u0433\u043e \u0432\u0438\u0434\u0436\u0435\u0442\u0430 <em>ui-&gt;comboBox<\/em><\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/076\/fed\/c53\/076fedc53471453cb1af859a491062fc.png\"\/><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u044d\u0442\u043e\u0442 \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 <\/p>\n<table cellpadding=\"5\">\n<tr>\n<td align=\"right\"> <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/4cf\/199\/782\/4cf19978227a430bb402d53dac9616b6.png\"\/> <\/td>\n<td><strong>ui-&gt;comboBox-&gt;setModel( new BaseComboModel( \u00abcountryname\u00bb, \u00abcountry\u00bb, this ) );<\/strong> <br \/>  <em>\u00abSELECT country.id, countryname FROM country\u00bb<\/em>. <br \/>  \u041f\u0440\u043e\u0441\u0442\u043e \u0441\u043f\u0438\u0441\u043e\u043a \u0441\u0442\u0440\u0430\u043d<\/td>\n<\/tr>\n<tr>\n<td align=\"right\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/b38\/f8f\/8cf\/b38f8f8cfd9649129b1f3b98f487a12a.png\"\/><\/td>\n<td><strong>ui-&gt;comboBox-&gt;setModel( new BaseComboModel( \u00abcountryname\u00bb, \u00abcountry WHERE countrycode IN ( &#8216;US&#8217;, &#8216;RU&#8217;, &#8216;CN&#8217; )\u00bb, this ) );<\/strong> <br \/>  <em>\u00abSELECT country.id, countryname FROM country WHERE countrycode IN ( \u201eUS\u201c, \u201eRU\u201c, \u201eCN\u201c )\u00bb<\/em>. <br \/>  \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0442\u0440\u0430\u043d\u044b \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u0435 \u043f\u043e \u043a\u043e\u0434\u0443.   <\/td>\n<\/tr>\n<tr>\n<td align=\"right\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/e20\/146\/e42\/e20146e426f34344b7e54425efd0af08.png\"\/><\/td>\n<td><strong>ui-&gt;comboBox-&gt;setModel( new BaseComboModel( \u00ablastname\u00bb, \u00abpersons\u00bb, this ) );<\/strong> <br \/>  <em>\u00abSELECT persons.id,, lastname FROM persons\u00bb<\/em>. <br \/>  \u0421\u043f\u0438\u0441\u043e\u043a \u0444\u0430\u043c\u0438\u043b\u0438\u0439 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0445 \u0432 \u0431\u0430\u0437\u0435. \u0427\u0442\u043e \u0431\u044b \u043e\u043d\u0438 \u0431\u044b\u043b\u0438, \u043d\u0430\u0434\u043e \u043a\u043b\u0438\u043a\u043d\u0443\u0442\u044c \u043a\u043d\u043e\u043f\u043a\u0443 \u00abFill test data\u00bb<\/td>\n<\/tr>\n<tr>\n<td align=\"right\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/62e\/1f3\/dc8\/62e1f3dc83c146af8768ad8ce31d6bfb.png\"\/><\/td>\n<td><strong>ui-&gt;comboBox-&gt;setModel( new BaseComboModel( \u00ablastname || &#8216; \u2014 &#8216; || email\u00bb, \u00abpersons LEFT JOIN address AS a ON a.id = persons.addressid\u00bb, this ) );<\/strong> <br \/>  <em>\u00abSELECT persons.id, lastname || &#8216; \u2014 &#8216; || email FROM persons LEFT JOIN address AS a ON a.id = persons.addressid\u00bb<\/em>. <br \/>  \u0421\u043f\u0438\u0441\u043e\u043a \u0444\u0430\u043c\u0438\u043b\u0438\u0439 \u0441 email a\u0434\u0440\u0435\u0441\u0430\u043c\u0438. \u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439\u0442\u0435 \u0447\u0442\u043e <em>&quot;||&quot;<\/em> \u043e\u043f\u0435\u0440\u0430\u0442\u043e\u0440 \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u0438 \u0441\u0442\u0440\u043e\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u0432 SQLite. \u0414\u043b\u044f \u0434\u0440\u0443\u0433\u0438\u0445 \u0431\u0430\u0437 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u0430\u0442\u044c \u043a\u043e\u043d\u043a\u0430\u0442\u0435\u043d\u0430\u0446\u0438\u044e<\/td>\n<\/tr>\n<tr>\n<td><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/190\/33f\/686\/19033f6865b74638ab37ef6be5e16ff4.png\"\/><\/td>\n<td><strong>ui-&gt;comboBox-&gt;setModel( new BaseComboModel( \u00ablastname || &#8216; \u2014 &#8216; || countryname\u00bb, \u00abpersons INNER JOIN address AS a ON a.id = persons.addressid INNER JOIN country AS c ON a.countryid = c.id\u00bb, this ) );<\/strong> <br \/>  <em>\u00abSELECT persons.id, lastname || &#8216; \u2014 &#8216; || countryname FROM persons INNER JOIN address AS a ON a.id = persons.addressid INNER JOIN country AS c ON a.countryid = c.id\u00bb<\/em>. <br \/>  \u0421\u043f\u0438\u0441\u043e\u043a \u0444\u0430\u043c\u0438\u043b\u0438\u0439 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u0441\u0442\u0440\u0430\u043d\u0430\u043c\u0438<\/td>\n<\/tr>\n<\/table>\n<p>  \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0432\u0441\u0435 \u044d\u0442\u0438 \u0444\u043e\u043a\u0443\u0441\u044b \u0441 <em>\u00abJOIN\u00bb<\/em> \u0438 <em>\u00abWHERE\u00bb<\/em> \u0432\u044b\u0433\u043b\u044f\u0434\u044f\u0442 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e. \u041d\u043e \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b. \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0438 \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0430 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u0443\u0434\u0430 SQL \u0437\u0430\u043f\u0440\u043e\u0441 \u0446\u0435\u043b\u0438\u043a\u043e\u043c. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u0432\u0441\u0435 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u0432 \u043e\u0434\u043d\u043e\u0439 \u0442\u0430\u0431\u043b\u0438\u0446\u0435. \u0418 \u0440\u0430\u0437\u0434\u0435\u043b\u044f\u0435\u0442\u0435 \u044d\u0442\u0438 \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f \u043f\u043e \u043a\u0430\u043a\u043e\u043c\u0443-\u0442\u043e \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u043c\u0443 \u043a\u043b\u044e\u0447\u0443. \u041b\u0443\u0447\u0448\u0435 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0442\u0440\u0435\u0442\u0438\u0439 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440, \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0433\u043e \u043a\u043b\u044e\u0447\u0430. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0430\u0437 <em>\u00abWHERE\u00bb<\/em>.<br \/>  \u041f\u043e\u0432\u0442\u043e\u0440\u044e\u0441\u044c, \u043a\u0430\u043a \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c <em>\u00abid\u00bb<\/em> \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0438 <br \/>  <em>ui-&gt;comboBox-&gt;itemData( ui-&gt;comboBox-&gt;currentIndex(), Qt::UserRole );<\/em><\/p>\n<h1>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h1>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/cd7\/83e\/63f\/cd783e63f909417581c8de41352e7798.png\"\/><\/p>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0441\u043b\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043a\u043e\u0434\u0430. \u0412\u044b \u0438\u0437\u0432\u043b\u0435\u043a\u043b\u0438 \u0447\u0442\u043e \u0442\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e\u0435 \u0434\u043b\u044f \u0441\u0435\u0431\u044f. \u0415\u0441\u043b\u0438 \u0445\u043e\u0442\u0438\u0442\u0435 \u0443\u0437\u043d\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 \u00abAddressBook\u00bb \u043f\u0440\u0438\u0432\u0435\u0434\u0451\u043d\u043d\u043e\u043c \u0437\u0434\u0435\u0441\u044c \u0440\u0430\u0434\u0438 \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u0421\u043c\u043e\u0442\u0440\u0438\u0442\u0435 \u0441\u0442\u0430\u0442\u044c\u044e <a href=\"https:\/\/habrahabr.ru\/post\/328670\/\">\u00ab\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0437\u0430\u0446\u0438\u044f \u043e\u0431\u043c\u0435\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 Qt \u0444\u043e\u0440\u043c \u0441 SQL \u0431\u0430\u0437\u043e\u0439 \u0434\u0430\u043d\u043d\u044b\u0445\u00bb.<\/a><\/p>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/329228\/\"> https:\/\/habrahabr.ru\/post\/329228\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/web\/251\/8f9\/a9a\/2518f9a9a8644242b9d9fed43f4fe7e0.png\"\/><\/p>\n<p>  \u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u0425\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441 \u0432\u0430\u043c\u0438 \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438, \u043a\u0430\u043a \u043c\u043e\u0436\u043d\u043e \u0438 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0434\u043b\u044f \u0432\u0438\u0434\u0436\u0435\u0442\u043e\u0432 \u0442\u0438\u043f\u0430 <em>QComboBox<\/em> \u0432 Qt. \u0412 \u043a\u043e\u043d\u0446\u0435 \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u0435, \u0434\u043b\u044f \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0431\u043e\u0431\u043e\u043a\u0441\u0430 \u0438\u0437 \u0411\u0414, \u043e\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u043e\u0439 \u043a\u043e\u0434\u0430.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-286702","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/286702","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=286702"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/286702\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=286702"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=286702"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=286702"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}