QML import does faild



  • 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


  • Moderators

    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.


Log in to reply
 

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