QmlRegisterType with shared library inside subdirs
Solved
QML and Qt Quick
-
Goodmorning,
I'm using Qt 5.11 and I'm creating a project composed by two subprojects:- SysInfo, a singleton shared library with its implementation, SysInfoLinuxImpl.
- Performance, a QML application.
Basically, I want that SysInfoLinuxImpl Q_PROPERTIES to be visible in QML subProject.
For this purpose, I tried to register SysinfoLinuxImpl with qmlRegisterType, but main.cpp doesn't recognize #include "SysInfoLinuxImpl.h" since it's contained in a different subdirs (the shared library) respect main.cpp (the QML application).
Could you help me? Thank you in advance.
Below some code.TEMPLATE = subdirs SUBDIRS += \ SysInfo \ Performance unix:!macx: LIBS += -L$$OUT_PWD/SysInfo/ -lSysInfo INCLUDEPATH += $$PWD/SysInfo DEPENDPATH += $$PWD/SysInfo Performance.depends = SysInfo
Sysinfo.h code
#include "sysinfo_global.h" #include <QObject> class SYSINFOSHARED_EXPORT SysInfo { public: static SysInfo& instance(); virtual ~SysInfo(); virtual void init() = 0; virtual double cpuLoadAverage() = 0; virtual double memoryUsed() = 0; protected: explicit SysInfo(); private: SysInfo(const SysInfo& rhs); SysInfo& operator= (const SysInfo& rhs); };
SysInfoImpl.h
#ifndef SYSINFOLINUXIMPL_H #define SYSINFOLINUXIMPL_H #include <QtGlobal> #include <QVector> #include <QFile> #include <QIODevice> #include <QTimer> #include <QThread> #include "sysinfo.h" #include "sysinfo_global.h" #include "sysinfolinuxworker.h" #include <QObject> class SYSINFOSHARED_EXPORT SysInfoLinuxImpl : public QObject, public SysInfo { Q_OBJECT Q_PROPERTY(double mCpuLoadAverage READ cpuLoadAverage) Q_PROPERTY(double mMemoryUsed READ memoryUsed) public: SysInfoLinuxImpl(); void init() override; double cpuLoadAverage() override; double memoryUsed() override; // Calculation are done on a separate thread and get by these slots public slots: void memoryCalculationDone(double percent) {mMemoryUsed = percent;} void cpuCalculationDone(double percent) {mCpuLoadAverage = percent;} private: QVector<qulonglong> cpuRawData(); public: QVector<qulonglong> mCpuLoadLastValues; double mCpuLoadAverage; double mMemoryUsed; private: QTimer mTimer; QThread mThread; }; #endif // SYSINFOLINUXIMPL_H
-
Hi,
When having sub-projects with libraries. What I usually do is to create one .pri file per library that contains the
INCLUDEPATH
andLIBS
statement necessary to use it and include that .pri file where needed in the other sub-projects. -