Creating C++ objects in QML [solved]



  • 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]


  • Moderators

    Can you show us the contents of recording.h

    Maybe an Uppercase typo?



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

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


  • Moderators

    Good deal you solved it.

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



  • Done! Enjoy your Saturday!


Log in to reply
 

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