Home

Hosting the AnalogClock widget in a .Net application

Introduction

This example provides a simple application that hosts the MonthCalendar winforms control from a .Net application.

The Qt analog clock running in a .Net application.

Hosting the AnalogClock widget.

Before the instantiation of the QtWidgetHost the application must make sure that the QtWinForms is initialized properly by calling QtWinFormsUtils::initQtForWindowsForms():

 /****************************************************************************
 **
 ** Copyright (C) 2003-2008 Trolltech ASA. All rights reserved.
 **
 ** This file is part of a Qt Solutions component.
 **
 ** Licensees holding a valid Qt Solutions License Agreement may use this
 ** file in accordance with the rights, responsibilities, and obligations
 ** contained therein. Please consult your licensing agreement or contact
 ** [email protected] if any conditions of this licensing are not clear
 ** to you.
 **
 ** Further information about Qt Solutions licensing is available at:
 ** http://www.trolltech.com/products/qt/addon/solutions/
 ** or by contacting [email protected].
 **
 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 **
 ****************************************************************************/
 #include "mainwindow.h"
 #include <qtwinforms.h>

 int main(int /*argc*/, char /*argv[]*/)
 {
     QtWinFormsUtils::initQtForWindowsForms();
     Application::EnableVisualStyles();
     Application::Run(gcnew MainWindow());
     return 0;
 }

Instantiation of the QtWidgetHost is done in the constructor of the MainWindow class:

 MainWindow::MainWindow()
 {
     SuspendLayout();

     clock = new AnalogClock();
     clockHost = gcnew QtWidgetHost(clock);
     ...
 }


Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt Solutions