0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the documentation of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
/*!
|
|
43 |
\example activeqt/comapp
|
|
44 |
\title COM App Example (ActiveQt)
|
|
45 |
|
|
46 |
The COM App example shows how to use ActiveQt to develop a Qt
|
|
47 |
application that can be automated via COM. Different QObject
|
|
48 |
based classes are exposed as COM objects that communicate with the
|
|
49 |
GUI of the running Qt application. The APIs of those COM objects
|
|
50 |
has been designed to resemble the APIs of standard COM
|
|
51 |
applications; i.e. those from Microsoft Office.
|
|
52 |
|
|
53 |
\snippet examples/activeqt/comapp/main.cpp 2
|
|
54 |
The first class \c Application represents the application object. It
|
|
55 |
exposes read-only properties \c documents and \c id to get access to the
|
|
56 |
list of documents, and an identifier. A read/write property \c visible
|
|
57 |
controls whether the QTabWidget-based user interface of the application
|
|
58 |
should be visible, and a slot \c quit() terminates the application.
|
|
59 |
|
|
60 |
The \e RegisterObject attribute is set to make sure that instances of this
|
|
61 |
class are registered in COM's running object table (ROT) - this allows COM
|
|
62 |
clients to connect to an already instantiated COM object.
|
|
63 |
|
|
64 |
\snippet examples/activeqt/comapp/main.cpp 1
|
|
65 |
The \c DocumentList class stores a list of documents. It provides an API
|
|
66 |
to read the number of documents, to access each document by index and to
|
|
67 |
create a new document. The \c application property returns the root object.
|
|
68 |
|
|
69 |
\snippet examples/activeqt/comapp/main.cpp 0
|
|
70 |
|
|
71 |
The \c Document class finally represents a document in the application.
|
|
72 |
Each document is represented by a page in the application's tab widget, and
|
|
73 |
has a title that is readable and writable through the document's API.
|
|
74 |
The \c application property again returns the root object.
|
|
75 |
|
|
76 |
\snippet examples/activeqt/comapp/main.cpp 3
|
|
77 |
The implementation of the \c Document class creates a new page for the tab
|
|
78 |
widget, and uses the title of that page for the title property. The page
|
|
79 |
is deleted when the document is deleted.
|
|
80 |
|
|
81 |
\snippet examples/activeqt/comapp/main.cpp 4
|
|
82 |
The \c DocumentList implementation is straightforward.
|
|
83 |
|
|
84 |
\snippet examples/activeqt/comapp/main.cpp 5
|
|
85 |
The \c Application class initializes the user interface in the constructor,
|
|
86 |
and shows and hides it in the implementation of \c setVisible(). The object
|
|
87 |
name (accessible through the \c id property) is set to \c "From QAxFactory"
|
|
88 |
to indicate that this COM object has been created by COM. Note that there is
|
|
89 |
no destructor that would delete the QTabWidget - this is instead done in the
|
|
90 |
\c quit() slot, before calling QApplication::quit() through a single-shot-timer,
|
|
91 |
which is necessary ensure that the COM call to the slot is complete.
|
|
92 |
|
|
93 |
\snippet examples/activeqt/comapp/main.cpp 6
|
|
94 |
The classes are exported from the server using the QAxFactory macros. Only
|
|
95 |
\c Application objects can be instantiated from outside - the other APIs can
|
|
96 |
only be used after accessing the respective objects throught the \c Application
|
|
97 |
API.
|
|
98 |
|
|
99 |
\snippet examples/activeqt/comapp/main.cpp 7
|
|
100 |
The main() entry point function creates a QApplication, and just enters the
|
|
101 |
event loop if the application has been started by COM. If the application
|
|
102 |
has been started by the user, then the \c Application object is created and
|
|
103 |
the object name is set to "From Application". Then the COM server is started,
|
|
104 |
and the application object is registered with COM. It is now accessible to
|
|
105 |
COM clients through the client-specific APIs.
|
|
106 |
|
|
107 |
Application exiting is controlled explicitly - if COM started the application,
|
|
108 |
then the client code has to call quit(); if the user started the application,
|
|
109 |
then the application terminates when the last window has been closed.
|
|
110 |
|
|
111 |
Finally, the user interface is made visible, and the event loop is started.
|
|
112 |
|
|
113 |
A simple Visual Basic application could now access this Qt application. In VB,
|
|
114 |
start a new "Standard Exe" project and add a project reference to the comappLib
|
|
115 |
type library. Create a form with a listbox "DocumentList", a static label
|
|
116 |
"DocumentsCount" and a command button "NewDocument". Finally, implement the code
|
|
117 |
for the form like this:
|
|
118 |
|
|
119 |
\snippet doc/src/snippets/code/doc_src_examples_activeqt_comapp.qdoc 0
|
|
120 |
|
|
121 |
To build the example you must first build the QAxServer library.
|
|
122 |
Then run \c qmake and your make tool in
|
|
123 |
\c{examples\activeqt\comapp}.
|
|
124 |
*/
|