diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/declarative/declarative.pro | 1 | ||||
-rw-r--r-- | examples/declarative/stringlistmodel/main.cpp | 76 | ||||
-rw-r--r-- | examples/declarative/stringlistmodel/stringlistmodel.pro | 9 | ||||
-rw-r--r-- | examples/declarative/stringlistmodel/stringlistmodel.qrc | 5 | ||||
-rw-r--r-- | examples/declarative/stringlistmodel/view.qml | 15 |
5 files changed, 106 insertions, 0 deletions
diff --git a/examples/declarative/declarative.pro b/examples/declarative/declarative.pro index 98ea6c4..e37c3d4 100644 --- a/examples/declarative/declarative.pro +++ b/examples/declarative/declarative.pro @@ -5,6 +5,7 @@ SUBDIRS = \ extending \ imageprovider \ objectlistmodel \ + stringlistmodel \ plugins \ proxywidgets diff --git a/examples/declarative/stringlistmodel/main.cpp b/examples/declarative/stringlistmodel/main.cpp new file mode 100644 index 0000000..abbffa7 --- /dev/null +++ b/examples/declarative/stringlistmodel/main.cpp @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include <qdeclarativeengine.h> +#include <qdeclarativecontext.h> +#include <qdeclarative.h> +#include <qdeclarativeitem.h> +#include <qdeclarativeview.h> + + +/* + This example illustrates exposing a QStringList as a + model in QML +*/ + +int main(int argc, char ** argv) +{ + QApplication app(argc, argv); + + QDeclarativeView view; + + QStringList dataList; + dataList.append("Item 1"); + dataList.append("Item 2"); + dataList.append("Item 3"); + dataList.append("Item 4"); + + QDeclarativeContext *ctxt = view.rootContext(); + ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); + + view.setSource(QUrl("qrc:view.qml")); + view.show(); + + return app.exec(); +} + diff --git a/examples/declarative/stringlistmodel/stringlistmodel.pro b/examples/declarative/stringlistmodel/stringlistmodel.pro new file mode 100644 index 0000000..23dc481 --- /dev/null +++ b/examples/declarative/stringlistmodel/stringlistmodel.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET = stringlistmodel +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp +RESOURCES += stringlistmodel.qrc diff --git a/examples/declarative/stringlistmodel/stringlistmodel.qrc b/examples/declarative/stringlistmodel/stringlistmodel.qrc new file mode 100644 index 0000000..17e9301 --- /dev/null +++ b/examples/declarative/stringlistmodel/stringlistmodel.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>view.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/stringlistmodel/view.qml b/examples/declarative/stringlistmodel/view.qml new file mode 100644 index 0000000..41c03d9 --- /dev/null +++ b/examples/declarative/stringlistmodel/view.qml @@ -0,0 +1,15 @@ +import Qt 4.7 + +ListView { + width: 100 + height: 100 + anchors.fill: parent + model: myModel + delegate: Component { + Rectangle { + height: 25 + width: 100 + Text { text: modelData } + } + } +} |