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. QML import does faild
Forum Updated to NodeBB v4.3 + New Features

QML import does faild

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 790 Views 2 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.
  • R Offline
    R Offline
    richard_h
    wrote on last edited by p3c0
    #1

    Hello,

    I'm triying to build an application with QML. But I have some Problems with the import of the QML and QtQuick. I have build a little prototype which only loads the QML-file or return an error string.

    Here is the code of my main.cpp

    #include <QCoreApplication>
    #include <QtQml/QQmlEngine>
    #include <QtQml/QQmlContext>
    #include <QtQml/QQmlComponent>
    #include <QDebug>
    
    int main(int argc, char *argv[]) {
        QCoreApplication a(argc, argv);
        QQmlEngine engine;
        QQmlComponent component(&engine);
        component.loadUrl(QUrl("application.qml"));
        
       if ( component.isReady() ) {
               component.create();
        } else {
            qWarning() << component.errorString();
        }
        QObject::connect(&engine, SIGNAL(quit()), QCoreApplication::instance(),SLOT(quit()));
        return a.exec();
    } 
    

    My application.qml

    import QtQml 2.0
    Item {
        function readValues(anArray, anObject) {
            for (var i=0; i<anArray.length; i++)
                console.log("Array item:", anArray[i])
            for (var prop in anObject) {
                console.log("Object item:", prop, "=", anObject[prop])
            }
        }
    }
    

    My pro-file

    QT       += core qml
    QT       -= gui
    TARGET = QMLPrototype
    CONFIG   += console
    CONFIG   -= app_bundle
    TEMPLATE = app
    SOURCES += main.cpp
    OTHER_FILES += application.qml
    

    If I start the application I get following error string:
    "file:///home/hoehne/src/QMLPrototype/application.qml:3 Item is not a type"

    I located the problem at the import of QML, because the Qt Creator said that I have to set the variable QML_IMPORT_PATH. So I set the Path with the following command:
    "export QML_IMPORT_PATH=/Qt_PATH/Qt-5.4.1/qml/" and now I see the import paths in the creator to Qt-5.4.1/qml and Qt-5.4.1/imports, but the problem is the same.

    I had build Qt without QtQuick support and build Qt new, because maybe the error is there. I have used following configuration:
    ./configure -static -commercial -no-xinput2 -no-opengl -no-eglfs -no-kms -qt-xcb -qt-sql-mysql -qt-sql-sqlite -system-libjpeg -system-libpng -nomake examples -skip wayland -prefix /usr/local/Trolltech/Qt-5.4.1
    and build it with GCC 4.9 at openSUSE 13.2x64. But the problem stays.

    If I import QtQuick instead of QML (in the qml-file), I don't get the error from Qt Creator, but following error string:
    file:///home/hoehne/src/QMLPrototype/application.qml:1 module "QtQuick" is not installed

    Has anybody the same problem or a solution how could I solve my problem?
    Thank you
    Richard

    p3c0P 1 Reply Last reply
    0
    • R richard_h

      Hello,

      I'm triying to build an application with QML. But I have some Problems with the import of the QML and QtQuick. I have build a little prototype which only loads the QML-file or return an error string.

      Here is the code of my main.cpp

      #include <QCoreApplication>
      #include <QtQml/QQmlEngine>
      #include <QtQml/QQmlContext>
      #include <QtQml/QQmlComponent>
      #include <QDebug>
      
      int main(int argc, char *argv[]) {
          QCoreApplication a(argc, argv);
          QQmlEngine engine;
          QQmlComponent component(&engine);
          component.loadUrl(QUrl("application.qml"));
          
         if ( component.isReady() ) {
                 component.create();
          } else {
              qWarning() << component.errorString();
          }
          QObject::connect(&engine, SIGNAL(quit()), QCoreApplication::instance(),SLOT(quit()));
          return a.exec();
      } 
      

      My application.qml

      import QtQml 2.0
      Item {
          function readValues(anArray, anObject) {
              for (var i=0; i<anArray.length; i++)
                  console.log("Array item:", anArray[i])
              for (var prop in anObject) {
                  console.log("Object item:", prop, "=", anObject[prop])
              }
          }
      }
      

      My pro-file

      QT       += core qml
      QT       -= gui
      TARGET = QMLPrototype
      CONFIG   += console
      CONFIG   -= app_bundle
      TEMPLATE = app
      SOURCES += main.cpp
      OTHER_FILES += application.qml
      

      If I start the application I get following error string:
      "file:///home/hoehne/src/QMLPrototype/application.qml:3 Item is not a type"

      I located the problem at the import of QML, because the Qt Creator said that I have to set the variable QML_IMPORT_PATH. So I set the Path with the following command:
      "export QML_IMPORT_PATH=/Qt_PATH/Qt-5.4.1/qml/" and now I see the import paths in the creator to Qt-5.4.1/qml and Qt-5.4.1/imports, but the problem is the same.

      I had build Qt without QtQuick support and build Qt new, because maybe the error is there. I have used following configuration:
      ./configure -static -commercial -no-xinput2 -no-opengl -no-eglfs -no-kms -qt-xcb -qt-sql-mysql -qt-sql-sqlite -system-libjpeg -system-libpng -nomake examples -skip wayland -prefix /usr/local/Trolltech/Qt-5.4.1
      and build it with GCC 4.9 at openSUSE 13.2x64. But the problem stays.

      If I import QtQuick instead of QML (in the qml-file), I don't get the error from Qt Creator, but following error string:
      file:///home/hoehne/src/QMLPrototype/application.qml:1 module "QtQuick" is not installed

      Has anybody the same problem or a solution how could I solve my problem?
      Thank you
      Richard

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

      Hi @richard_h ,
      As you can see here, Item requires an import of QtQuick and as you say you have build Qt without it, that error is ofcourse expected. Also QtQuick is heavily depended on OpenGL and I see you have opted to not include it during configuration. Try compiling Qt with OpenGL support and QtQuick.

      157

      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