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. [Solved] Having trouble using QDeclarativeView
Forum Updated to NodeBB v4.3 + New Features

[Solved] Having trouble using QDeclarativeView

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 4 Posters 2.7k 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.
  • E Offline
    E Offline
    Endless
    wrote on last edited by
    #1

    I'm trying to get a QML file to run from my C++ program. I looked on the Nokia website, and they have tips posted on how to do it. I got the following code directly from the Nokia website: http://get.qt.nokia.com/training/QtQuickforCppDevelopers/slides/qml-cpp-integration.pdf

    @
    #include <QApplication>
    #include <QDeclarativeView>
    #include <QUrl>

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QDeclarativeView view;
    view.setSource(QUrl("qrc:files/animation.qml"));
    view.show();
    
    return app.exec&#40;&#41;;
    

    }
    @

    This seems pretty easy and straightforward, right? I put this in Qt Creator, and I get an error when I try to build: QDeclarativeView: No such file or directory. This is the first among 4 errors.

    The closest library I could find is <QtDeclarative/QDeclarativeView>, but when I include this, it doesn't work either. Why doesn't code work that's right on the Nokia website? What am I doing wrong here?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on last edited by
      #2

      You will have to add
      @
      QT += declarative
      @
      to your .pro file. This has to be done for every Qt module you are going to use besides core (which is set automatically). Others are for example gui, network, xml.

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Endless
        wrote on last edited by
        #3

        That wasn't hard at all. Thanks for the info. My pro file already had QT += core. Do I add a "" to the end of this line and put declarative on the next line, or do I even need core?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          You do need core.

          You can do:

          @
          QT += core declarative
          @
          or
          @
          QT += core
          declarative
          @
          or
          @
          QT += core
          QT += declarative
          @

          They're all equivalent.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • C Offline
            C Offline
            cpscotti
            wrote on last edited by
            #5

            Don't forget you'll need that qml file properly referenced in the resources file (hence the qrc:/) with appropriate path and/or prefix..

            cpscotti.com/blog/ - Used when I need to kill some time at work :D

            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