summaryrefslogtreecommitdiffstats
path: root/doc/src/getting-started/tutorials.qdoc
blob: a7f6421d8f6f47850826a8d6b2cee2da69793fc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/****************************************************************************
**
** 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 documentation 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$
**
****************************************************************************/

/*!
    \page tutorials.html
    \title Tutorials

    \contentspage How to Learn Qt
    \nextpage Qt Examples

    \brief Tutorials, guides and overviews to help you learn Qt.

    \nextpage Qt Examples

    A collection of tutorials and "walkthrough" guides are provided with Qt to
    help new users get started with Qt development. These documents cover a
    range of topics, from basic use of widgets to step-by-step tutorials that
    show how an application is put together.

    \table
    \row
    \o{2,1} \l{Widgets Tutorial}{\bold Widgets}
    \o{2,1} \l{Address Book Tutorial}{\bold {Address Book}}
    \row
    \o \image widget-examples.png Widgets
    \o
    A beginner's guide to getting started with widgets and layouts to create
    GUI applications.

    \o \image addressbook-tutorial.png AddressBook
    \o
    A seven part guide to creating a fully-functioning address book
    application. This tutorial is also available with
    \l{Tutoriel "Carnet d'adresses"}{French explanation}.

    \row
    \o{2,1} \l{A Quick Start to Qt Designer}{\bold{Qt Designer}}
    \o{2,1} \l{Qt Linguist Manual: Programmers#Tutorials}{\bold {Qt Linguist}}
    \row
    \o \image designer-examples.png QtDesigner
    \o
    A quick guide through \QD showing the basic steps to create a
    form with this interactive tool.

    \o \image linguist-examples.png QtLinguist
    \o
    A guided tour through the translations process, explaining the
    tools provided for developers, translators and release managers.

    \row
    \o{2,1} \l{QTestLib Tutorial}{\bold QTestLib}
    \o{2,1} \l{qmake Tutorial}{\bold qmake}
    \row
    \o{2,1}
    This tutorial gives a short introduction to how to use some of the
    features of Qt's unit-testing framework, QTestLib. It is divided into
    four chapters.

    \o{2,1}
    This tutorial teaches you how to use \c qmake. We recommend that
    you read the \l{qmake Manual}{qmake user guide} after completing
    this tutorial.

    \endtable
*/
ss="hl opt">[name] except KeyError: pass try: yield finally: for name in names: try: del sys.modules[name] except KeyError: pass @contextlib.contextmanager def import_state(**kwargs): """Context manager to manage the various importers and stored state in the sys module. The 'modules' attribute is not supported as the interpreter state stores a pointer to the dict that the interpreter uses internally; reassigning to sys.modules does not have the desired effect. """ originals = {} try: for attr, default in (('meta_path', []), ('path', []), ('path_hooks', []), ('path_importer_cache', {})): originals[attr] = getattr(sys, attr) if attr in kwargs: new_value = kwargs[attr] del kwargs[attr] else: new_value = default setattr(sys, attr, new_value) if len(kwargs): raise ValueError( 'unrecognized arguments: {0}'.format(kwargs.keys())) yield finally: for attr, value in originals.items(): setattr(sys, attr, value) class mock_modules(object): """A mock importer/loader.""" def __init__(self, *names): self.modules = {} for name in names: if not name.endswith('.__init__'): import_name = name else: import_name = name[:-len('.__init__')] if '.' not in name: package = None elif import_name == name: package = name.rsplit('.', 1)[0] else: package = import_name module = imp.new_module(import_name) module.__loader__ = self module.__file__ = '<mock __file__>' module.__package__ = package module.attr = name if import_name != name: module.__path__ = ['<mock __path__>'] self.modules[import_name] = module def __getitem__(self, name): return self.modules[name] def find_module(self, fullname, path=None): if fullname not in self.modules: return None else: return self def load_module(self, fullname): if fullname not in self.modules: raise ImportError else: sys.modules[fullname] = self.modules[fullname] return self.modules[fullname] def __enter__(self): self._uncache = uncache(*self.modules.keys()) self._uncache.__enter__() return self def __exit__(self, *exc_info): self._uncache.__exit__(None, None, None) class ImportModuleTests(unittest.TestCase): """Test importlib.import_module.""" def test_module_import(self): # Test importing a top-level module. with mock_modules('top_level') as mock: with import_state(meta_path=[mock]): module = importlib.import_module('top_level') self.assertEqual(module.__name__, 'top_level') def test_absolute_package_import(self): # Test importing a module from a package with an absolute name. pkg_name = 'pkg' pkg_long_name = '{0}.__init__'.format(pkg_name) name = '{0}.mod'.format(pkg_name) with mock_modules(pkg_long_name, name) as mock: with import_state(meta_path=[mock]): module = importlib.import_module(name) self.assertEqual(module.__name__, name) def test_shallow_relative_package_import(self): modules = ['a.__init__', 'a.b.__init__', 'a.b.c.__init__', 'a.b.c.d'] with mock_modules(*modules) as mock: with import_state(meta_path=[mock]): module = importlib.import_module('.d', 'a.b.c') self.assertEqual(module.__name__, 'a.b.c.d') def test_deep_relative_package_import(self): # Test importing a module from a package through a relatve import. modules = ['a.__init__', 'a.b.__init__', 'a.c'] with mock_modules(*modules) as mock: with import_state(meta_path=[mock]): module = importlib.import_module('..c', 'a.b') self.assertEqual(module.__name__, 'a.c') def test_absolute_import_with_package(self): # Test importing a module from a package with an absolute name with # the 'package' argument given. pkg_name = 'pkg' pkg_long_name = '{0}.__init__'.format(pkg_name) name = '{0}.mod'.format(pkg_name) with mock_modules(pkg_long_name, name) as mock: with import_state(meta_path=[mock]): module = importlib.import_module(name, pkg_name) self.assertEqual(module.__name__, name) def test_relative_import_wo_package(self): # Relative imports cannot happen without the 'package' argument being # set. self.assertRaises(TypeError, importlib.import_module, '.support') def test_main(): from test.test_support import run_unittest run_unittest(ImportModuleTests) if __name__ == '__main__': test_main()