Creating C++ objects in QML [solved]
-
wrote on 5 Apr 2014, 13:56 last edited by
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(QStringLiteral("qml/Games/recordCurrentSong.qml")); viewer.showExpanded(); return app.exec();
}
@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_01Additional 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.cppInstallation path
target.path =
Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()OTHER_FILES +=
qml/Games/doRecordingView.qmlHEADERS +=
recording.h
@[edit: please add @ tags around your code for better readability , Eddy]
-
wrote on 5 Apr 2014, 14:03 last edited by
Can you show us the contents of recording.h
Maybe an Uppercase typo?
-
wrote on 5 Apr 2014, 14:20 last edited by
I just got it! Thanks Eddy - I needed to add #include <QtQml>
First time I see something calling c++ from QML. I'm excited. :-)
-
wrote on 5 Apr 2014, 14:21 last edited by
Good deal you solved it.
Please edit your first post and add [solved] in your title.
-
wrote on 5 Apr 2014, 14:24 last edited by
Done! Enjoy your Saturday!
1/5