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. Creating C++ objects in QML [solved]

Creating C++ objects in QML [solved]

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 1.3k Views
  • 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.
  • T Offline
    T Offline
    thready
    wrote on last edited by
    #1

    Hi!

    Not sure trying to do this from QGuiApplication makes sense. I'm getting "undeclared identifier " from the qmlRegisterType line in my main function:

    @
    #include <QtGui/QGuiApplication>
    #include "qtquick2applicationviewer.h"
    #include <QQmlEngine>

    #include "recording.h"

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

    qmlRegisterType<Recording>("Games", 1, 0, "Recording");
    
    QtQuick2ApplicationViewer viewer;
    viewer.setMainQmlFile&#40;QStringLiteral("qml/Games/recordCurrentSong.qml"&#41;&#41;;
    viewer.showExpanded(&#41;;
    
    return app.exec&#40;&#41;;
    

    }
    @

    Can someone point me in the right direction? I've done lots of reading and not enough tinkering to start understanding all this properly... Many thanks

    Mike

    ps - in case it's pertinent, here's the Games.pro file:

    @

    Add more folders to ship with the application, here

    folder_01.source = qml/Games
    folder_01.target = qml
    DEPLOYMENTFOLDERS = folder_01

    Additional import path used to resolve QML modules in Creator's code model

    QML_IMPORT_PATH =

    The .cpp file which was generated for your project. Feel free to hack it.

    SOURCES += main.cpp
    recording.cpp

    Installation path

    target.path =

    Please do not modify the following two lines. Required for deployment.

    include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
    qtcAddDeployment()

    OTHER_FILES +=
    qml/Games/doRecordingView.qml

    HEADERS +=
    recording.h
    @

    [edit: please add @ tags around your code for better readability , Eddy]

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      Can you show us the contents of recording.h

      Maybe an Uppercase typo?

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thready
        wrote on last edited by
        #3

        I just got it! Thanks Eddy - I needed to add #include <QtQml>

        First time I see something calling c++ from QML. I'm excited. :-)

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          Good deal you solved it.

          Please edit your first post and add [solved] in your title.

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • T Offline
            T Offline
            thready
            wrote on last edited by
            #5

            Done! Enjoy your Saturday!

            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