defs
Posts: 10
Joined: Wed Jul 27, 2016 1:23 pm

QtQuick weird behaviour

Wed Jul 27, 2016 1:35 pm

I have trouble with this simple application. It will respond very slowly (processor usage is over 90%) if I have background picture or just pure Rectangle (id: background in example bellow) before button, if I comment this background rectangle, application would react quickly, but if I add "enable.layers: true" to root item, slow response would be come back .
Where is the problem?
I would like to have background picture and fast response on clicking.
I am running this example on Raspberry Pi 3.

Code: Select all

import QtQuick 2.3


Item {
    id: root
    visible: true
    width: 800
    height: 480


    Rectangle {
        id: background
        anchors.fill: parent
        smooth: true

    }

    
    Rectangle {
        id: button
        width: 200 ; height: 123

        anchors.centerIn: parent

        smooth: true
        radius: 8

        //color the button with a gradient
        gradient: Gradient {
            GradientStop {
                position: 1.0
                color: {
                    if (mouseArea.pressed)
                        return "red"
                    else
                        return "chartreuse"
                }
            }
            GradientStop {position: 0.0; color: "paleturquoise" }
        }


        MouseArea {
            id:mouseArea
            anchors.fill: parent
            onPressed: {
                //handler.turnOn()
            }
            onReleased: {
               // handler.turnOff()
            }

        }
    }
}

UPDATE: When running this example with qmlviewer from terminal it works fast as expected (in that case have to use "import QtQuick 1.1" instead "2.3". When running with qmlscene from terminal or with QQuickView from C++ this app respond very bad on clicking button.

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: QtQuick weird behaviour

Wed Jul 27, 2016 2:10 pm

- Well, qmlviewer is Qt4 and not Qt5 so that explains why you have to import QtQuick 1.1.
- And you are doing this from a terminal window inside the desktop environment ? (just ot be sure).

defs
Posts: 10
Joined: Wed Jul 27, 2016 1:23 pm

Re: QtQuick weird behaviour

Wed Jul 27, 2016 2:17 pm

Yes, I am doing this from the desktop environment. Same thing happen if running from Qt Creator from main.cpp:

Code: Select all

#include <QGuiApplication>
#include <QQmlApplicationEngine>


#include <QCoreApplication>
#include <QDebug>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQmlComponent>
#include <QQuickView>


int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    //app.setOverrideCursor(QCursor(Qt::BlankCursor));

  
    QQuickView view;
    //view.engine()->rootContext()->setContextProperty("handler", &handler);
    view.setSource(QUrl("qrc:/main.qml"));
    view.show();
    //view.showFullScreen();



    return app.exec();
}

defs
Posts: 10
Joined: Wed Jul 27, 2016 1:23 pm

Re: QtQuick weird behaviour

Wed Jul 27, 2016 4:17 pm

Due this fact which I found in documentation: "In Qt 5, all QML applications are rendered with an OpenGL scenegraph architecture rather than the Graphics View framework used in Qt 4.", is it mean that I have problem with OpenGL at my Raspberry Pi3. Could somebody who has installed Qt5 on Raspberry try this example and see how fast button reacts if there is background rectangle?
I am wondering if it is bug or something like this, how come nobody didn't discover it yet?

User avatar
topguy
Posts: 6527
Joined: Tue Oct 09, 2012 11:46 am
Location: Trondheim, Norway

Re: QtQuick weird behaviour

Wed Jul 27, 2016 8:18 pm

Most people either don't use QML, or if they do they do it in fullscreen EGLFS mode which is supported on Raspberry Pi. ( but the Qt version compiled for Raspbian dont work so well with EGLFS because its compiled slightly wrong ). So for good OpenGL performance under X you probably have to enable the experimental OpenGL driver for X-Windows.

defs
Posts: 10
Joined: Wed Jul 27, 2016 1:23 pm

Re: QtQuick weird behaviour

Thu Jul 28, 2016 8:55 am

Yes, you are right, thank you very much. I enabled experimental GL under raspi-config and my example now works great. I noticed that welcome screen at Qt Creator is now messed up, but who cares... Also, I tried to split 128 MB memory for GPU but it was not good idea 'cos booting didn't succeeded, 64MB for GPU works great. Do you know what is happening in this situation?

Update: it seems there is too much problems with experimental GL, official 7" touch screen doesn't work, and raspbian crashes every now and then. It seems that best solution is to revert to Qt4 and QtQuick 1.1 or use EGLFS.

Return to “Graphics programming”