As if it weren't confusing enough I found this article https://web.archive.org/web/20211003125109/https://www.qt.io/blog/qml-type-registration-in-qt-5.15 which says we don't need qmlRegisterType but simplyh add QML_ELEMENT to my C++ class which I have done but still no luck when I do the import of Dataprocess, the URI defined in CMakeLIsts.txt.
Main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QtQml/QQmlExtensionPlugin.h>
Q_IMPORT_QML_PLUGIN(DataprocessPlugin)
Q_IMPORT_QML_PLUGIN(UtilitiesPlugin)
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(u"qrc:/FlightSimDataAnalyzer/main.qml"_qs);
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
&app, [url](QObject *obj, const QUrl &objUrl) {
if (!obj && url == objUrl)
QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
return app.exec();
}
Main projects CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(FlightSimDataAnalyzer VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 REQUIRED COMPONENTS
Quick
Qml
Core
)
qt_add_executable(appFlightSimDataAnalyzer
main.cpp
)
qt_add_qml_module(appFlightSimDataAnalyzer
URI FlightSimDataAnalyzer
VERSION 1.0
QML_FILES main.qml
)
add_subdirectory(Dataprocess)
add_subdirectory(Utilities)
set_target_properties(appFlightSimDataAnalyzer PROPERTIES
MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
target_link_libraries(appFlightSimDataAnalyzer
PRIVATE Qt6::Quick
data_processplugin
utilitiesplugin
)
install(TARGETS appFlightSimDataAnalyzer
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
CMakeLists.txt for QML and C++ files in the subdirectory.
qt_add_library(data_process STATIC)
qt_add_qml_module(data_process
URI "Dataprocess"
VERSION 1.0
QML_FILES
GetRawData.qml
SOURCES
dataprocess.h
dataprocess.cpp
)
The header file.
#ifndef DATAPROCESS_H
#define DATAPROCESS_H
#include <QObject>
#include <QDebug>
#include "qqmlintegration.h"
class DataProcess : public QObject
{
Q_OBJECT
QML_ELEMENT
public:
explicit DataProcess(QObject *parent = nullptr);
Q_INVOKABLE void rawdataprocess(QString sim, QString rawfile);
signals:
public slots:
private:
QString m_datafile;
};
#endif // DATAPROCESS_H
The C++ file
#include "dataprocess.h"
DataProcess::DataProcess(QObject *parent)
: QObject{parent}
{
}
void DataProcess::rawdataprocess(QString sim, QString rawfile)
{
qDebug() << "I am in processing.";
}