×

Discussion Board

Results 1 to 9 of 9
  1. #1
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    231

    Question QML Code in Qt Project

    Hi all,

    It is possible to use QML Code in Qt Project? For example to create a view?

    Best regards.

  2. #2
    Registered User
    Join Date
    Mar 2010
    Posts
    6

    Re: QML Code in Qt Project

    Hi,

    It is possible to use qml code in your existing QT project. For example you can use QDeclarativeView to integrate qml widgets into you QT project. Like below:

    QDeclarativeView *qmlView = new QDeclarativeView;
    qmlView->setSource(QUrl::fromLocalFile("myqml.qml"));

    QWidget *widget = myExistingWidget();
    QVBoxLayout *layout = new QVBoxLayout(widget);
    layout->addWidget(qmlView);

    Refer this for further detail.
    http://doc.qt.nokia.com/4.7-snapshot...tegration.html

    Best Regards,
    Ashish

  3. #3
    Super Contributor
    Join Date
    Mar 2008
    Posts
    1,481

  4. #4
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    231

    Re: QML Code in Qt Project

    Hi again,

    I have this code:

    in my .pro file:

    Code:
    ...
    content.sources = content\*
    content.path = content
    pics.sources = content\pics\*
    pics.path = pics
    DEPLOYMENT += content pics
    ...
    in the main():

    Code:
    /*
    ============================================================================
     Name		: Test.cpp
     Copyright   : Your copyright notice
     Description : Main GUI Application
    ============================================================================
    */
    
    #include <QtGui>
    #include <QApplication>
    
    #include <QDeclarativeView>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QDeclarativeView *view = new QDeclarativeView;
        view->setSource(QUrl::fromLocalFile("webbrowser.qml"));
        view->show();    
        return a.exec();
    }
    the webbrowser.qml file:

    Code:
    /****************************************************************************
    **
    ** 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 QtDeclarative module 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$
    **
    ****************************************************************************/
    
    import Qt 4.7
    import QtWebKit 1.0
    
    import "content"
    
    Rectangle {
        id: webBrowser
    
        property string urlString : "http://www.nokia.com/"
    
        width: 800; height: 600
        color: "#343434"
    
        FlickableWebView {
            id: webView
            url: webBrowser.urlString
            onProgressChanged: header.urlChanged = false
            anchors { top: headerSpace.bottom; left: parent.left; right: parent.right; bottom: parent.bottom }
        }
    
        Item { id: headerSpace; width: parent.width; height: 62 }
    
        Header {
            id: header
            editUrl: webBrowser.urlString
            width: headerSpace.width; height: headerSpace.height
        }
    
        ScrollBar {
            scrollArea: webView; width: 8
            anchors { right: parent.right; top: header.bottom; bottom: parent.bottom }
        }
    
        ScrollBar {
            scrollArea: webView; height: 8; orientation: Qt.Horizontal
            anchors { right: parent.right; rightMargin: 8; left: parent.left; bottom: parent.bottom }
        }
    }
    I have compiled (with Qt 4.7) and installed the project to 5800 XM Symbian device, but the web browser does not appear. What is wrong?

    Regards.
    Last edited by symbi4n_programmer; 2011-02-14 at 12:34.

  5. #5
    Super Contributor
    Join Date
    Mar 2008
    Posts
    1,481

    Re: QML Code in Qt Project

    Hi,

    I think two issues you could try.
    A. First try your qml file with QML viewer and see if that is OK
    B. When your QML file is OK, you can use Qt creator wizards to create an app that can load your QML file (In Qt creator File | New File or Project | Qt Quick Project | Qt Quick Application), You see a main.qml file has been generated and you replace the contents with the contents of your QML file.
    This works OK for me

  6. #6
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    231

    Re: QML Code in Qt Project

    Quote Originally Posted by mahbub_s60 View Post
    Hi,

    I think two issues you could try.
    A. First try your qml file with QML viewer and see if that is OK
    The QML file is OK because I have copied it from QtSDK/demos/4.7/declarative.

    I think that the problem is in the QML import clause: import "content", because if I use the next QML, this is showed correctly:

    Code:
    import QtQuick 1.0
    
    Rectangle {
         width: 300
         height: 300
    
         color: backgroundColor
    
         Text {
             anchors.centerIn: parent
             text: "Hello Yellow World!"
         }
    }
    My QML file imports others QML files:

    content/Button.qml
    content/FlickableWebView.qml
    content/Header.qml
    content/ScrollBar.qml
    content/UrlInput.qml

    Quote Originally Posted by mahbub_s60 View Post
    B. When your QML file is OK, you can use Qt creator wizards to create an app that can load your QML file (In Qt creator File | New File or Project | Qt Quick Project | Qt Quick Application), You see a main.qml file has been generated and you replace the contents with the contents of your QML file.
    This works OK for me
    I will try this.
    Last edited by symbi4n_programmer; 2011-02-14 at 14:10.

  7. #7
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    231

    Re: QML Code in Qt Project

    Quote Originally Posted by mahbub_s60 View Post
    B. When your QML file is OK, you can use Qt creator wizards to create an app that can load your QML file (In Qt creator File | New File or Project | Qt Quick Project | Qt Quick Application), You see a main.qml file has been generated and you replace the contents with the contents of your QML file.
    This works OK for me
    I tried it and the application worked correctly in the simulator.

    When I use Qt Creator the project runs correctly. If I use Carbide.c++ I get the next error:

    Code:
    undefined reference to `vtable for QmlApplicationViewer'
    What is wrong?

    Regards.

  8. #8
    Super Contributor
    Join Date
    Mar 2008
    Posts
    1,481

    Re: QML Code in Qt Project

    You should use Qt Creator here not Carbide C++. I think these are meant for Qt Creator not for Carbide C++

  9. #9
    Regular Contributor
    Join Date
    Feb 2009
    Posts
    231

    Re: QML Code in Qt Project

    Finally I have created a new project without Qt creator wizard and it has compiled correctly, I have used Carbide.c++, my code:

    Code:
    layout = new QVBoxLayout(this);
    
    QDeclarativeView *view = new QDeclarativeView;
    view->setResizeMode(QDeclarativeView::SizeViewToRootObject);
    view->showFullScreen();	
    view->setSource(QUrl::fromLocalFile("qml/photoviewer/photoviewer.qml"));
    
    layout->addWidget(view);
    setLayout(layout);
    I have used photoviewer example in my QT project: C:\QtSDK\Demos\4.7\declarative\photoviewer

    my .pro:

    Code:
    ...
    QT += core \
        gui \
        network \
        declarative
    ...
    qml.sources = qml\*
    qml.path = qml
    photoviewer.sources =     qml\photoviewer\*
    photoviewer.path =        qml\photoviewer
    i18n.sources =            qml\photoviewer\i18n\*
    i18n.path =               qml\photoviewer\i18n
    PhotoViewerCore.sources = qml\photoviewer\PhotoViewerCore\*
    PhotoViewerCore.path =    qml\photoviewer\PhotoViewerCore
    images.sources =          qml\photoviewer\PhotoViewerCore\images\*
    images.path =             qml\photoviewer\PhotoViewerCore\images
    script.sources =          qml\photoviewer\PhotoViewerCore\script\*
    script.path =             qml\photoviewer\PhotoViewerCore\script
    DEPLOYMENT += qml \
        photoviewer \
        i18n \
        PhotoViewerCore \
        images \
        script
    I have tested the project in 5800 XM and N97 but it runs slowly, is it normal? Is QML optimized only for Symbian^3 devices?

    Regards.
    Last edited by symbi4n_programmer; 2011-02-17 at 18:12.

Similar Threads

  1. [Qt QML] Questions regarding QML Performance
    By SeanZhang in forum [Archived] Qt Quick
    Replies: 1
    Last Post: 2011-05-05, 13:07

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •