Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Problem with importing self-developed component
Forum Updated to NodeBB v4.3 + New Features

Problem with importing self-developed component

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 1.3k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Eugene GromovE Offline
    Eugene GromovE Offline
    Eugene Gromov
    wrote on last edited by Eugene Gromov
    #1

    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);\
        app.setOrganizationName("QtProject");\
        app.setOrganizationDomain("qt-project.org");\
        app.setApplicationName(QFileInfo(app.applicationFilePath()).baseName());\
        QQuickView view;\
        if (qgetenv("QT_QUICK_CORE_PROFILE").toInt()) {\
            QSurfaceFormat f = view.format();\
            f.setProfile(QSurfaceFormat::CoreProfile);\
            f.setVersion(4, 4);\
            view.setFormat(f);\
        }\
        view.connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));\
        new QQmlFileSelector(view.engine(), &view);\
        view.setSource(QUrl("qrc:///" #NAME ".qml")); \
        view.setResizeMode(QQuickView::SizeRootObjectToView);\
        qmlRegisterType<Message>("com.myself", 1, 0, "GPIO1");    
    if (QGuiApplication::platformName() == QLatin1String("qnx") || \
              QGuiApplication::platformName() == QLatin1String("eglfs")) {\
            view.showFullScreen();\
        } else {\
            view.show();\
        }\
        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
    {
        Q_OBJECT
    public:
        explicit GPIO1(QObject *parent = 0) : QObject(parent){}
        Q_INVOKABLE int test(){
            return 1;
        }
    signals:
    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.

    best regards. Eugene Gromov
    evgeni.gromov@gmail.com

    p3c0P 1 Reply Last reply
    0
    • Eugene GromovE Eugene Gromov

      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);\
          app.setOrganizationName("QtProject");\
          app.setOrganizationDomain("qt-project.org");\
          app.setApplicationName(QFileInfo(app.applicationFilePath()).baseName());\
          QQuickView view;\
          if (qgetenv("QT_QUICK_CORE_PROFILE").toInt()) {\
              QSurfaceFormat f = view.format();\
              f.setProfile(QSurfaceFormat::CoreProfile);\
              f.setVersion(4, 4);\
              view.setFormat(f);\
          }\
          view.connect(view.engine(), SIGNAL(quit()), &app, SLOT(quit()));\
          new QQmlFileSelector(view.engine(), &view);\
          view.setSource(QUrl("qrc:///" #NAME ".qml")); \
          view.setResizeMode(QQuickView::SizeRootObjectToView);\
          qmlRegisterType<Message>("com.myself", 1, 0, "GPIO1");    
      if (QGuiApplication::platformName() == QLatin1String("qnx") || \
                QGuiApplication::platformName() == QLatin1String("eglfs")) {\
              view.showFullScreen();\
          } else {\
              view.show();\
          }\
          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
      {
          Q_OBJECT
      public:
          explicit GPIO1(QObject *parent = 0) : QObject(parent){}
          Q_INVOKABLE int test(){
              return 1;
          }
      signals:
      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.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

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

      157

      1 Reply Last reply
      0
      • Eugene GromovE Offline
        Eugene GromovE Offline
        Eugene Gromov
        wrote on last edited by
        #3

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

        best regards. Eugene Gromov
        evgeni.gromov@gmail.com

        p3c0P 1 Reply Last reply
        0
        • Eugene GromovE Eugene Gromov

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

          p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

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

          157

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi and welcome to devnet,

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            Eugene GromovE 1 Reply Last reply
            0
            • SGaistS SGaist

              Hi and welcome to devnet,

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

              Eugene GromovE Offline
              Eugene GromovE Offline
              Eugene Gromov
              wrote on last edited by
              #6

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

              best regards. Eugene Gromov
              evgeni.gromov@gmail.com

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved