Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to integrate c++ and qt quick(qml)
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved QML and Qt Quick
18 Posts 6 Posters 13.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imrrk
    wrote on last edited by
    #3

    hello ixsci

    have you succeeded in it

    1 Reply Last reply
    0
    • I Offline
      I Offline
      ixSci
      wrote on last edited by
      #4

      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.

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vsorokin
        wrote on last edited by
        #5

        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.

        --
        Vasiliy

        1 Reply Last reply
        0
        • I Offline
          I Offline
          imrrk
          wrote on last edited by
          #6

          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]

          1 Reply Last reply
          0
          • I Offline
            I Offline
            ixSci
            wrote on last edited by
            #7

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

            1 Reply Last reply
            0
            • V Offline
              V Offline
              vsorokin
              wrote on last edited by
              #8

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

              view->show();@

              --
              Vasiliy

              1 Reply Last reply
              0
              • I Offline
                I Offline
                imrrk
                wrote on last edited by
                #9

                ixsci

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

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  ixSci
                  wrote on last edited by
                  #10

                  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.

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    imrrk
                    wrote on last edited by
                    #11

                    ixsci

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

                    1 Reply Last reply
                    0
                    • I Offline
                      I Offline
                      imrrk
                      wrote on last edited by
                      #12

                      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

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        imrrk
                        wrote on last edited by
                        #13

                        hello vass

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

                        so please sort it out

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          DenisKormalev
                          wrote on last edited by
                          #14

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

                          P.S. And please don't multipost.

                          1 Reply Last reply
                          0
                          • I Offline
                            I Offline
                            imrrk
                            wrote on last edited by
                            #15

                            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

                            1 Reply Last reply
                            0
                            • V Offline
                              V Offline
                              vsorokin
                              wrote on last edited by
                              #16

                              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.

                              --
                              Vasiliy

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                mohsen
                                wrote on last edited by
                                #17

                                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.

                                1 Reply Last reply
                                0
                                • K Offline
                                  K Offline
                                  kamalakshantv
                                  wrote on last edited by
                                  #18

                                  [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.

                                  1 Reply Last reply
                                  0

                                  • Login

                                  • Login or register to search.
                                  • First post
                                    Last post
                                  0
                                  • Categories
                                  • Recent
                                  • Tags
                                  • Popular
                                  • Users
                                  • Groups
                                  • Search
                                  • Get Qt Extensions
                                  • Unsolved