In Sync with OutlookThis example is a modified version of the standard Qt addressbook example.It demonstrates the use of QAxObject and querySubObject to instantiate and navigate the Outlook Object Model, and the use of the Qt property system to read and write values of items in the Outlook contact folder. The modifications in the class declaration of the central widget are a forward declaration of the QAxObject class and the IDispatch interface, and a new QListViewItem subclass ABListViewItem that implements a constructor and a destructor and has a member contact_item of type QAxObject. class QAxObject; struct IDispatch; class ABListViewItem : public QListViewItem { public: ABListViewItem( QListView *listview, QString firstName, QString lastName, QString address, QString eMail, QAxObject *contact ); ~ABListViewItem(); QAxObject *contactItem() const; private: QAxObject *contact_item; }; The ABCentralWidget gets a destructor, a new protected function setupOutlook, a new protected slot updateOutlook, and also three members of type QAxObject. void findEntries(); void updateOutlook(); protected: void setupTabWidget(); void setupListView(); void setupOutlook(); QAxObject *outlook, *outlookSession, *contactItems; QGridLayout *mainGrid; The implementation of the ABListViewItem class is trivial: ABListViewItem::ABListViewItem( QListView *listview, QString firstName, QString lastName, QString address, QString eMail, QAxObject *contact ) : QListViewItem( listview, firstName, lastName, address, eMail ), contact_item( contact ) { } ABListViewItem::~ABListViewItem() { delete contact_item; } QAxObject *ABListViewItem::contactItem() const { return contact_item; }The ABCentralWidget constructor initializes the QAxObject pointers to zero and calls the setupOutlook function. The ABCentralWidget destructor calls the Logoff method of the outlookSession object. ABCentralWidget::ABCentralWidget( QWidget *parent, const char *name ) : QWidget( parent, name ), outlook( 0 ), outlookSession( 0 ), contactItems( 0 ) { mainGrid = new QGridLayout( this, 2, 1, 5, 5 ); setupTabWidget(); setupListView(); setupOutlook();The setupOutlook implementation creates a QAxObject to wrap the Outlook.Application COM object. void ABCentralWidget::setupOutlook() { outlook = new QAxObject( "Outlook.Application", this );The call to querySubObject returns a new QAxObject wrapper around the "Session" object of the Outlook Object hierarchy. If the call fails for some reason setupOutlook returns, otherwise it calls the "Logon" method of the Session object. // Get a session objectThe following call to querySubObject returns a new QAxObject wrapper around the default folder for "contacts". // Get the default folder for contacts QAxObject *defFolder = outlookSession->querySubObject( "GetDefaultFolder(OlDefaultFolders)", "olFolderContacts" );querySubObject is then used again to get the list of all items in the folder. The connect statement connects the new ABCentralWidget slot to the signals provided by the "Items" COM object. Finally, it calls the updateOutlook function to populate the listview. // Get all items if ( defFolder ) { contactItems = defFolder->querySubObject( "Items" ); connect( contactItems, SIGNAL(ItemAdd(IDispatch*)), this, SLOT(updateOutlook()) ); connect( contactItems, SIGNAL(ItemChange(IDispatch*)), this, SLOT(updateOutlook()) ); connect( contactItems, SIGNAL(ItemRemove()), this, SLOT(updateOutlook()) ); } updateOutlook(); } The implementation of the updateOutlook slot clears the listview, and uses querySubObject to iterate through the list of items. For every item provided a new ABListViewItem object is created and filled with the properties of the item object. The object returned by querySubObject is a child of the callee (ie. "contactItems"), but the list view item should take ownership to provide a cleaner relation between entries, so the item has to be removed from its parent object. void ABCentralWidget::updateOutlook() { The addEntry implementation calls the CreateItem method of the Outlook.Application object to create a new contact item, and creates a new ABListViewItem if the call succeeds. void ABCentralWidget::addEntry() { The changeEntry implementation updates the values in the contact item of the current listview item as well as the values of the listview item itself. void ABCentralWidget::changeEntry() { To build the example you must first build the QAxContainer library. Then run your make tool in examples/qutlook and run the resulting qutlok.exe. See also The QAxContainer Examples. |
Publicité
Best OfActualités les plus luesSemaine
Mois
Année
Le blog Digia au hasardDéploiement d'applications Qt Commercial sur les tablettes Windows 8Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.
CommunautéRessources
Liens utilesContact
Qt dans le magazine |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 3.2 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com