How to integrate c++ and qt quick(qml)



  • hello friends...i want to know..how to integrate c++ and qml...and run it on n97 mini....i have my 6 apps ready but as the ui is build in nokia qt sdk..its not very good..so i want to make good ui using qt quick and integrate with my c++ code...so help me out guys..

    thanks
    imrrk



  • You can start form "here":http://doc.trolltech.com/4.7-snapshot/qtbinding.html and continue further by following links in the tutorial. Also you can search through the Qt documentation for "QML in C++". I'm sure you will find a plenty of information



  • hello ixsci

    have you succeeded in it



  • I'm not using it for any production code yet. But I had created some useless test applications which were using C++ with QML. Have you any problem with this conjunction? Place your code with problem description and we will try to help you, if any.



  • You can start from this "link":http://doc.qt.nokia.com/4.7-snapshot/gettingstartedqml.html, if you need no english version of it document, you may find it "here":http://developer.qt.nokia.com/wiki/Category:Learning::GettingStarted.



  • hi ixsci

    I used qt creator rc version...created a new project and choosed qt mobile project ,then i added a new qml file (ran.qml)and return the below code..

    @
    import Qt 4.7

    Rectangle {

    id: myRect; width: 640; height: 400; state: "OldState"
    
    Rectangle { id: movingRect; width: 60; height: 60; color: "red"
    
        MouseArea { anchors.fill: parent;
    
               onClicked: if (myRect.state == "OldState") myRect.state = "NewState";
    
                               else myRect.state = "OldState" }
    }
    
    states: [
    
        State {
    
            name: "NewState"
    
            PropertyChanges { target: movingRect; x: 580; y: 340; radius: 30; color: "green" }
    
        }
    
    ]
    
    transitions: [
    
        Transition {
    
            from: "OldState"; to: "NewState"
    
            PropertyAnimation { properties: "x,y,color,radius"; duration: 1000 }
    
        },
    
        Transition {
    
            from: "NewState"; to: "OldState"
    
            PropertyAnimation { properties: "x,y,color,radius"; duration: 1000 }
    
        }
    ]
    

    }

    now i opened the main.cpp file and return the below code..

    #include "mainwindow.h"
    #include <QtGui/QApplication>
    #include<QtDeclarative/QDeclarativeEngine>
    #include<QtDeclarative/QDeclarativeComponent>
    #include<QtDeclarative/QDeclarativeItem>
    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    MainWindow mainWindow;
    
    QDeclarativeEngine *engine = new QDeclarativeEngine;
    
    QDeclarativeComponent component(engine, QUrl::fromLocalFile&#40;"ran.qml"&#41;&#41;;
    
    QObject *myObject = component.create(&#41;;
    
    QDeclarativeItem *item = qobject_cast<QDeclarativeItem*>(myObject);
    
    mainWindow.setOrientation(MainWindow::ScreenOrientationAuto);
    
    mainWindow.showExpanded();
    
    return app.exec(&#41;;
    

    }
    @
    so tell me whether its correct????

    Thanks
    imrrk@@

    [EDIT: added @-tags for code formatting, Volker]



  • Your example isn't full for showing qml. Why just not to follow examples from the above?



  • You need widget, try this:
    @
    #include <QtDeclarative/QDeclarativeView>
    ...
    QDeclarativeView *view = new QDeclarativeView;
    view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
    mainWindow->setCentralWidget(view);

    view->show();@



  • ixsci

    I tried this from the link u gave...can you soty out the errors



  • Your code has one C++ mistake:QDeclarativeItem* item = qobject_cast<QDeclarativeItem*>(myObject);
    You will see nothing with your corrected code though. You must create scene for showing QML in it. I have no handy example for this but Vass presented simplified way to show QML in C++ code. Just follow the Vass code. When you master it you can move further to more complex examples with your own created scenes, if you will need any. But at the moment it would be better to use pre-created QDeclarativeView for comprehending rudiments of C++ and QML relationship.



  • ixsci

    Ok wait i will try out vass code and let you know



  • ixsci

    By using Vass code

    I getting fllowing errors
    1.C:\Qt\qtcreator-2.0.94\intgmobile-build-simulator/../intgmobile/main.cpp:14: error: undefined reference to `_imp___ZN16QDeclarativeViewC1EP7QWidget'

    2.C:\Qt\qtcreator-2.0.94\intgmobile-build-simulator/../intgmobile/main.cpp:18: error: undefined reference to `_imp___ZN16QDeclarativeView9setSourceERK4QUrl'

    3.:-1: error: collect2: ld returned 1 exit status



  • hello vass

    I am getting the above errors by using ur code..

    so please sort it out



  • imrrk, add
    @QT += declarative@
    to your .pro file.

    P.S. And please don't multipost.



  • Hi everyone
    I tried with all the possibilities listed here...the example works fine in simulator but when i try to deploy it on device using Nokia Qt SDK i m getting error as follows

    1.DeclarativeView no such file or directory



  • imrrk What i version of Qt on your device? For Qt quick you need install "developers build Qt 4.7":http://wiki.forum.nokia.com/index.php/Qt_4.7_for_Symbian^3_-_developer_version.



  • Hello,
    I had same problem with WinCE. You should manually copy QtDeclarative, QtNetwork, QtScript and QtSql libraries to device when you use QML in your project. Also make sure you're using the latest QtSDK version.



  • [quote author="imrrk" date="1293685687"]Hi everyone
    I tried with all the possibilities listed here...the example works fine in simulator but when i try to deploy it on device using Nokia Qt SDK i m getting error as follows

    1.DeclarativeView no such file or directory
    [/quote]

    The latest Nokia Qt SDK available has support for Qt 4.6 only for release builds. So you cannot build QML app release with this SDK.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.