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.