Problem with importing self-developed component

  • Hello! I am trying to develop my component for GPIO control and embed it in my Qt application using the code below:

    #include <QDir>
    #include <QGuiApplication>
    #include <QQmlEngine>
    #include <QQmlFileSelector>
    #include <QQuickView> 
    #include "GPIO1.h"
    #include "GPIO1.cpp"
    [#define DECLARATIVE_EXAMPLE_MAIN(NAME) int main(int argc, char* argv[]) \
        QGuiApplication app(argc,argv);\
        QQuickView view;\
        if (qgetenv("QT_QUICK_CORE_PROFILE").toInt()) {\
            QSurfaceFormat f = view.format();\
            f.setVersion(4, 4);\
        view.connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));\
        new QQmlFileSelector(view.engine(), &view);\
        view.setSource(QUrl("qrc:///" #NAME ".qml")); \
        qmlRegisterType<Message>("com.myself", 1, 0, "GPIO1");    
    if (QGuiApplication::platformName() == QLatin1String("qnx") || \
              QGuiApplication::platformName() == QLatin1String("eglfs")) {\
        } else {\
        return app.exec();\

    The code of my component is in file gpio1.h:

    #ifndef GPIO1_H
    #define GPIO1_H
    #include <QObject>
    class GPIO1 : public QObject
        explicit GPIO1(QObject *parent = 0) : QObject(parent){}
        Q_INVOKABLE int test(){
            return 1;
    public slots:
    #endif // GPIO1_H

    QML imports are:

    import QtQuick 2.0
    import QtQuick.Controls 1.3
    import com.myself 1.0

    Application compiles successfull, the QML editor recognises GPIO1 as an item. but when i run application, I'am having the error message:

    "module com.myself is not installed"

    I would appreciate any help.

  • Moderators

    Hi @Eugene-Gromov,
    You have registered the component after loading the QML file. It should be done before it.

  • Thank you very much, @p3c0 problem solved now :)

  • Moderators

    @Eugene-Gromov Congratulations :)
    Also please use ``` (3 bacticks) for posting code blocks.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Out of curiosity: why are you including GPIO1.cpp in your main.cpp ?

  • @SGaist, during development I replaced implementation to .h file, forgot to remove #include. Will knock my code into shape :)

Log in to reply

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