Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED] Qt5, QtQuick 2, HelloWorld application, issue with QQuickView



  • Hello,
    I am trying to compile and run a very simple HelloWorld application using Qt5 and QML (QtQuick 2).
    i added the following in the .pro file:
    @QT += quick@

    My main.cpp file looks like:
    @#include <QCoreApplication>
    #include <QtQuick/QQuickView>

    Q_DECL_EXPORT int main(int argc, char *argv[])
    {
    QCoreApplication app(argc, argv, 5);

    QQuickView *  viewer = new QQuickView;
    //viewer.setOrientation(QQuickView::ScreenOrientationAuto);
    viewer->setSource(QUrl("qml/helloWorldQT5/main.qml"));
    viewer->show();
    
    return app.exec&#40;&#41;;
    

    }
    @

    My main.qml file looks like:
    @import QtQuick 2.0

    Rectangle {
    width: 360
    height: 360
    Text {
    text: qsTr("Hello World")
    anchors.centerIn: parent
    }
    MouseArea {
    anchors.fill: parent
    onClicked: {
    Qt.quit();
    }
    }
    }@

    The compilation and link of this source code is alright.
    But there is a runtime error occuring while performing the following:
    @QQuickView * viewer = new QQuickView;@

    if I run it in debug mode, I've got a NULL pointer in the following function inside qguiapplication.cpp:
    @QFont QGuiApplication::font()
    {
    QMutexLocker locker(applicationFontMutex());
    if (!QGuiApplicationPrivate::app_font)
    QGuiApplicationPrivate::app_font =
    new QFont(QGuiApplicationPrivate::platformIntegration()->fontDatabase()->defaultFont());
    return *QGuiApplicationPrivate::app_font;
    }@

    The QGuiApplicationPrivate::platformIntegration() value is apparently NULL.
    Has anyone any hint to help me there?

    I built the qt5 using the following command line:
    @./configure -confirm-license -opensource -no-multimedia -no-phonon -debug -declarative -v8 -opengl -nomake examples -nomake tests -prefix ~/qt5bin -developer-build@

    (there might be an error using both prefix and -developer-build in the same time I think :) )



  • Also the Application Output looks like this:
    @Debugging starts
    &"warning: GDB: Failed to set controlling terminal: Invalid argument\n"
    .dynamic section for "/lib/libpthread.so.0" is not at the expected address
    difference appears to be caused by prelink, adjusting expectations
    .dynamic section for "/lib/libm.so.6" is not at the expected address
    difference appears to be caused by prelink, adjusting expectations
    .dynamic section for "/usr/lib/libpng12.so.0" is not at the expected address
    difference appears to be caused by prelink, adjusting expectations
    .dynamic section for "/lib/libdl.so.2" is not at the expected address
    difference appears to be caused by prelink, adjusting expectations
    .dynamic section for "/lib/libgthread-2.0.so.0" is not at the expected address
    difference appears to be caused by prelink, adjusting expectations
    .dynamic section for "/lib/librt.so.1" is not at the expected address
    difference appears to be caused by prelink, adjusting expectations
    .dynamic section for "/usr/lib/libXdamage.so.1" is not at the expected address
    difference appears to be caused by prelink, adjusting expectations
    .dynamic section for "/usr/lib/libdrm.so.2" is not at the expected address
    difference appears to be caused by prelink, adjusting expectations
    .dynamic section for "/usr/lib/libXau.so.6" is not at the expected address
    difference appears to be caused by prelink, adjusting expectations
    Qml debugging is enabled. Only use this in a safe environment!
    can't find linker symbol for virtual table for QQuickView' value foundQDeclarativeJS::IR::BasicBlock::JUMP(QDeclarativeJS::IR::BasicBlock*)' instead@



  • try adding declarative to QT in .pro file i.e:

    @QT += quick declarative@



  • I added your suggestion, the crash / segmentation fault is still occuring :(

    The stack looks like this when the segmentation fault occurs:
    @0 QGuiApplication::font qguiapplication.cpp 1333 0x6dd26f1
    1 QFont::QFont qfont.cpp 685 0x6e58ec1
    2 QDeclarativeFontValueType::QDeclarativeFontValueType qdeclarativevaluetype.cpp 221 0xa32ce8
    3 QDeclarativeValueTypeFactory::valueType qdeclarativevaluetype.cpp 159 0xa312f6
    4 QDeclarativeValueTypeFactory::QDeclarativeValueTypeFactory qdeclarativevaluetype.cpp 84 0xa30e22
    5 QDeclarativeEnginePrivate::QDeclarativeEnginePrivate qdeclarativeengine.cpp 347 0x9a49f0
    6 QDeclarativeEngine::QDeclarativeEngine qdeclarativeengine.cpp 504 0x9a56ff
    7 QQuickViewPrivate::QQuickViewPrivate qquickview.cpp 70 0x383875
    8 QQuickView::QQuickView qquickview.cpp 159 0x383d48
    9 main main.cpp 8 0x8048a3e
    @



  • It is now working with a simple declaration change:
    QCoreApplication -> QGuiApplication
    ah!

    @
    #include <QtQuick/QQuickView>
    #include <QGuiApplication>

    Q_DECL_EXPORT int main(int argc, char *argv[])
    {

    QGuiApplication app(argc, argv, 5);
    
    QQuickView viewer;
    //viewer.setOrientation(QQuickView::ScreenOrientationAuto);
    viewer.setSource(QUrl("qml/helloWorldQT5/main.qml"));
    viewer.show();
    
    return app.exec();
    

    }
    @



  • It worked for me too.

    My problem was also the fact that I had to create a .pro manually because using the one generated by QtCreator was not working (I got this error: qmlapplicationviewer/qmlapplicationviewer.cpp:15:30: fatal error: QtGui/QApplication: No such file or directory)

    so I just used:

    @SOURCES +=
    main.cpp

    OTHER_FILES +=
    qml/Test/main.qml

    QT += quick

    install_it.path = $${M_BUILDDIR}

    for(FILE, OTHER_FILES){
    install_it.files += $${FILE}
    }

    INSTALLS += install_it@



  • Hi,

    I am tried to build a very simple QtQuick 2.0 project with Qt 5.0.0 and Qt Creator 2.6.1. I made a new project, selected the "Qt Quick 2 Application (Built-in Elements)", set the name and press "next -> next ... etc".

    If I run the application, I get a simple window with white background and the "Hello World" text.

    If I open the main.qml file, I found in the editor the following message in a label:
    "Unsupported QtQuick version(0:0)
    Go to error"

    I click on the "Go to error", I see the following line in the text editor:
    @
    import QtQuick 2.0
    @

    It is a first line in main.qml file.

    Can somebody help me to can use the QTQuick 2.0 too?

    Regards,
    Norbert



  • Current version of a built-in designer in QtCreator doesn`t support QtQuick 2.
    You need to use Text Editor for your main.qml and to study writting UI in QMLanguage.


Log in to reply