1

What I am trying to do is to create several qml windows and change their content via c++ (slots signals). The problem that occured to me now is that although the qml-content (like text) is updated but not properly redrawn.

The result looks like this: qml: 2 windows

However, with only one window everything works perfectly fine.

I am using Qt 5.5.0 + Xubuntu 14.04

So the question is: How can I force these windows to refresh properly ?

minimal example how to reproduce:

main.cpp:

#include <QGuiApplication>
#include <QQmlApplicationEngine>

#include "myclass.h"

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

    QQmlApplicationEngine engine;
    MyClass obj(engine);

    return app.exec();
}

myclass.h:

#ifndef MYCLASS_H
#define MYCLASS_H

#include <QObject>
#include <QQmlApplicationEngine>
#include <QQmlContext>


class MyClass : public QObject
{
    Q_OBJECT
public:

    explicit MyClass(QQmlApplicationEngine& engine) : QObject()
    {
        engine.rootContext()->setContextProperty("myObj", this);
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

        startTimer(400);
    }

    void timerEvent(QTimerEvent *e)
    {
        static int i = 0;
        emit intIncreased(++i);
    }

signals:
    void intIncreased(int myint);
};

#endif // MYCLASS_H

main.qml:

import QtQuick 2.5
import QtQuick.Window 2.2

Window {
    visible: true

    Connections {
        target: myObj
        onIntIncreased: myText.text = myint
    }

    Text {
        id: myText
        font.pixelSize: 100
        anchors.centerIn: parent
    }
}

edit: works flawless on my Mac btw, so I guess it's a platform related issue.

HMH
  • 111
  • 4
  • Hmm... I think it's bad idea to load same root `QML` file twice. What will be a root item here? Try instead to create several `QQuickView` objects on same `QQmlApplicationEngine`. – folibis Aug 31 '15 at 00:48
  • Qt 5.5.0 doesn't seem to support linux well. My Mint have encountered memory leak when running qml. Last night, I tried the emitter example and then the machine was stucked. So, Maybe you can try Qt 5.4.2 – Zen Aug 31 '15 at 01:00

1 Answers1

0

Finally I figured what was going wrong: My OpenGL version was inappropriate. I solved my problem by following the instructions posted here: https://stackoverflow.com/a/20589728 This made a newer version available to my application and now it runs better, though not perfectly fine (somtimes refreshing is stuck for a short time, well but I think it's the best I can get atm).

Community
  • 1
  • 1
HMH
  • 111
  • 4