A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQSqlTableModel</id>
		<title>C++/Qt/QSqlTableModel - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C%2B%2B%2FQt%2FQSqlTableModel"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QSqlTableModel&amp;action=history"/>
		<updated>2026-04-18T22:11:59Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QSqlTableModel&amp;diff=1224&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QSqlTableModel&amp;diff=1224&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:06Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QSqlTableModel&amp;diff=1225&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C%2B%2B/Qt/QSqlTableModel&amp;diff=1225&amp;oldid=prev"/>
				<updated>2010-05-25T10:25:12Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==QSqlTableModel demo==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;  &lt;br /&gt;
/****************************************************************************&lt;br /&gt;
**&lt;br /&gt;
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).&lt;br /&gt;
** All rights reserved.&lt;br /&gt;
** Contact: Nokia Corporation (qt-info@nokia.com)&lt;br /&gt;
**&lt;br /&gt;
** This file is part of the examples of the Qt Toolkit.&lt;br /&gt;
**&lt;br /&gt;
** $QT_BEGIN_LICENSE:LGPL$&lt;br /&gt;
** Commercial Usage&lt;br /&gt;
** Licensees holding valid Qt Commercial licenses may use this file in&lt;br /&gt;
** accordance with the Qt Commercial License Agreement provided with the&lt;br /&gt;
** Software or, alternatively, in accordance with the terms contained in&lt;br /&gt;
** a written agreement between you and Nokia.&lt;br /&gt;
**&lt;br /&gt;
** GNU Lesser General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU Lesser&lt;br /&gt;
** General Public License version 2.1 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.LGPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU Lesser General Public License version 2.1 requirements&lt;br /&gt;
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.&lt;br /&gt;
**&lt;br /&gt;
** In addition, as a special exception, Nokia gives you certain additional&lt;br /&gt;
** rights.  These rights are described in the Nokia Qt LGPL Exception&lt;br /&gt;
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.&lt;br /&gt;
**&lt;br /&gt;
** GNU General Public License Usage&lt;br /&gt;
** Alternatively, this file may be used under the terms of the GNU&lt;br /&gt;
** General Public License version 3.0 as published by the Free Software&lt;br /&gt;
** Foundation and appearing in the file LICENSE.GPL included in the&lt;br /&gt;
** packaging of this file.  Please review the following information to&lt;br /&gt;
** ensure the GNU General Public License version 3.0 requirements will be&lt;br /&gt;
** met: http://www.gnu.org/copyleft/gpl.html.&lt;br /&gt;
**&lt;br /&gt;
** If you have questions regarding the use of this file, please contact&lt;br /&gt;
** Nokia at qt-info@nokia.com.&lt;br /&gt;
** $QT_END_LICENSE$&lt;br /&gt;
**&lt;br /&gt;
****************************************************************************/&lt;br /&gt;
#ifndef CONNECTION_H&lt;br /&gt;
#define CONNECTION_H&lt;br /&gt;
#include &amp;lt;QMessageBox&amp;gt;&lt;br /&gt;
#include &amp;lt;QSqlDatabase&amp;gt;&lt;br /&gt;
#include &amp;lt;QSqlError&amp;gt;&lt;br /&gt;
#include &amp;lt;QSqlQuery&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
    This file defines a helper function to open a connection to an&lt;br /&gt;
    in-memory SQLITE database and to create a test table.&lt;br /&gt;
    If you want to use another database, simply modify the code&lt;br /&gt;
    below. All the examples in this directory use this function to&lt;br /&gt;
    connect to a database.&lt;br /&gt;
*/&lt;br /&gt;
static bool createConnection()&lt;br /&gt;
{&lt;br /&gt;
    QSqlDatabase db = QSqlDatabase::addDatabase(&amp;quot;QSQLITE&amp;quot;);&lt;br /&gt;
    db.setDatabaseName(&amp;quot;:memory:&amp;quot;);&lt;br /&gt;
    if (!db.open()) {&lt;br /&gt;
        QMessageBox::critical(0, qApp-&amp;gt;tr(&amp;quot;Cannot open database&amp;quot;),&lt;br /&gt;
            qApp-&amp;gt;tr(&amp;quot;Unable to establish a database connection.\n&amp;quot;&lt;br /&gt;
                     &amp;quot;This example needs SQLite support. Please read &amp;quot;&lt;br /&gt;
                     &amp;quot;the Qt SQL driver documentation for information how &amp;quot;&lt;br /&gt;
                     &amp;quot;to build it.\n\n&amp;quot;&lt;br /&gt;
                     &amp;quot;Click Cancel to exit.&amp;quot;), QMessageBox::Cancel);&lt;br /&gt;
        return false;&lt;br /&gt;
    }&lt;br /&gt;
    QSqlQuery query;&lt;br /&gt;
    query.exec(&amp;quot;create table person (id int primary key, &amp;quot;&lt;br /&gt;
               &amp;quot;firstname varchar(20), lastname varchar(20))&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into person values(101, &amp;quot;Danny&amp;quot;, &amp;quot;Young&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into person values(102, &amp;quot;Christine&amp;quot;, &amp;quot;Holand&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into person values(103, &amp;quot;Lars&amp;quot;, &amp;quot;Gordon&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into person values(104, &amp;quot;Roberto&amp;quot;, &amp;quot;Robitaille&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into person values(105, &amp;quot;Maria&amp;quot;, &amp;quot;Papadopoulos&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;create table offices (id int primary key,&amp;quot;&lt;br /&gt;
                                             &amp;quot;imagefile int,&amp;quot;&lt;br /&gt;
                                             &amp;quot;location varchar(20),&amp;quot;&lt;br /&gt;
                                             &amp;quot;country varchar(20),&amp;quot;&lt;br /&gt;
                                             &amp;quot;description varchar(100))&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into offices &amp;quot;&lt;br /&gt;
               &amp;quot;values(0, 0, &amp;quot;Oslo&amp;quot;, &amp;quot;Norway&amp;quot;,&amp;quot;&lt;br /&gt;
               &amp;quot;&amp;quot;Oslo is home to more than 500 000 citizens and has a &amp;quot;&lt;br /&gt;
               &amp;quot;lot to offer.It has been called \&amp;quot;The city with the big &amp;quot;&lt;br /&gt;
               &amp;quot;heart\&amp;quot; and this is a nickname we are happy to live up to.&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into offices &amp;quot;&lt;br /&gt;
               &amp;quot;values(1, 1, &amp;quot;Brisbane&amp;quot;, &amp;quot;Australia&amp;quot;,&amp;quot;&lt;br /&gt;
               &amp;quot;&amp;quot;Brisbane is the capital of Queensland, the Sunshine State, &amp;quot;&lt;br /&gt;
               &amp;quot;where it is beautiful one day, perfect the next.  &amp;quot;&lt;br /&gt;
               &amp;quot;Brisbane is Australia&amp;quot;&amp;quot;s 3rd largest city, being home &amp;quot;&lt;br /&gt;
               &amp;quot;to almost 2 million people.&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into offices &amp;quot;&lt;br /&gt;
               &amp;quot;values(2, 2, &amp;quot;Redwood City&amp;quot;, &amp;quot;US&amp;quot;,&amp;quot;&lt;br /&gt;
               &amp;quot;&amp;quot;You find Redwood City in the heart of the Bay Area &amp;quot;&lt;br /&gt;
               &amp;quot;just north of Silicon Valley. The largest nearby city is &amp;quot;&lt;br /&gt;
               &amp;quot;San Jose which is the third largest city in California &amp;quot;&lt;br /&gt;
               &amp;quot;and the 10th largest in the US.&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into offices &amp;quot;&lt;br /&gt;
               &amp;quot;values(3, 3, &amp;quot;Berlin&amp;quot;, &amp;quot;Germany&amp;quot;,&amp;quot;&lt;br /&gt;
               &amp;quot;&amp;quot;Berlin, the capital of Germany is dynamic, cosmopolitan &amp;quot;&lt;br /&gt;
               &amp;quot;and creative, allowing for every kind of lifestyle. &amp;quot;&lt;br /&gt;
               &amp;quot;East meets West in the metropolis at the heart of a &amp;quot;&lt;br /&gt;
               &amp;quot;changing Europe.&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into offices &amp;quot;&lt;br /&gt;
               &amp;quot;values(4, 4, &amp;quot;Munich&amp;quot;, &amp;quot;Germany&amp;quot;,&amp;quot;&lt;br /&gt;
               &amp;quot;&amp;quot;Several technology companies are represented in Munich, &amp;quot;&lt;br /&gt;
               &amp;quot;and the city is often called the \&amp;quot;Bavarian Silicon Valley\&amp;quot;. &amp;quot;&lt;br /&gt;
               &amp;quot;The exciting city is also filled with culture, &amp;quot;&lt;br /&gt;
               &amp;quot;art and music. &amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into offices &amp;quot;&lt;br /&gt;
               &amp;quot;values(5, 5, &amp;quot;Beijing&amp;quot;, &amp;quot;China&amp;quot;,&amp;quot;&lt;br /&gt;
               &amp;quot;&amp;quot;Beijing as a capital city has more than 3000 years of &amp;quot;&lt;br /&gt;
               &amp;quot;history. Today the city counts 12 million citizens, and &amp;quot;&lt;br /&gt;
               &amp;quot;is the political, economic and cultural centre of China.&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;create table images (locationid int, file varchar(20))&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into images values(0, &amp;quot;images/oslo.png&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into images values(1, &amp;quot;images/brisbane.png&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into images values(2, &amp;quot;images/redwood.png&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into images values(3, &amp;quot;images/berlin.png&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into images values(4, &amp;quot;images/munich.png&amp;quot;)&amp;quot;);&lt;br /&gt;
    query.exec(&amp;quot;insert into images values(5, &amp;quot;images/beijing.png&amp;quot;)&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
#endif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;QtGui&amp;gt;&lt;br /&gt;
#include &amp;lt;QtSql&amp;gt;&lt;br /&gt;
#include &amp;quot;../connection.h&amp;quot;&lt;br /&gt;
void initializeModel(QSqlTableModel *model)&lt;br /&gt;
{&lt;br /&gt;
    model-&amp;gt;setTable(&amp;quot;person&amp;quot;);&lt;br /&gt;
    model-&amp;gt;setEditStrategy(QSqlTableModel::OnManualSubmit);&lt;br /&gt;
    model-&amp;gt;select();&lt;br /&gt;
    model-&amp;gt;setHeaderData(0, Qt::Horizontal, QObject::tr(&amp;quot;ID&amp;quot;));&lt;br /&gt;
    model-&amp;gt;setHeaderData(1, Qt::Horizontal, QObject::tr(&amp;quot;First name&amp;quot;));&lt;br /&gt;
    model-&amp;gt;setHeaderData(2, Qt::Horizontal, QObject::tr(&amp;quot;Last name&amp;quot;));&lt;br /&gt;
}&lt;br /&gt;
QTableView *createView(const QString &amp;amp;title, QSqlTableModel *model)&lt;br /&gt;
{&lt;br /&gt;
    QTableView *view = new QTableView;&lt;br /&gt;
    view-&amp;gt;setModel(model);&lt;br /&gt;
    view-&amp;gt;setWindowTitle(title);&lt;br /&gt;
    return view;&lt;br /&gt;
}&lt;br /&gt;
int main(int argc, char *argv[])&lt;br /&gt;
{&lt;br /&gt;
    QApplication app(argc, argv);&lt;br /&gt;
    if (!createConnection())&lt;br /&gt;
        return 1;&lt;br /&gt;
    QSqlTableModel model;&lt;br /&gt;
    initializeModel(&amp;amp;model);&lt;br /&gt;
    QTableView *view1 = createView(QObject::tr(&amp;quot;Table Model (View 1)&amp;quot;), &amp;amp;model);&lt;br /&gt;
    QTableView *view2 = createView(QObject::tr(&amp;quot;Table Model (View 2)&amp;quot;), &amp;amp;model);&lt;br /&gt;
    view1-&amp;gt;show();&lt;br /&gt;
    view2-&amp;gt;move(view1-&amp;gt;x() + view1-&amp;gt;width() + 20, view1-&amp;gt;y());&lt;br /&gt;
    view2-&amp;gt;show();&lt;br /&gt;
    return app.exec();&lt;br /&gt;
}&lt;br /&gt;
   &lt;br /&gt;
    &lt;br /&gt;
  &amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>