How to repaint QWidget encapsulated in QDeclarativeItem in QML?
-
@p3c0 Unfortunately specifying with and height did not solve the issue.
I created a minimal project (with QtQuick Application template). It is using QCustomPlot and everything works fine. But this is a Desktop version, and if I am not mistaken it is using Qt 5.3, but I need it to work on my embedded linux Qt 4.8 version.
The embedded linux version usesqmlapplicationviewer
to load QML files with this comment on top:# This file was generated by the Qt Quick Application wizard of Qt Creator. # The code below adds the QmlApplicationViewer to the project and handles the # activation of QML debugging.
the desktop version uses
qtquickapplicationviewer
:# This file was generated by the Qt Quick 1 Application wizard of Qt Creator. # The code below adds the QtQuick1ApplicationViewer to the project.
I'm not sure if the applicationviewer or the qt version difference causes my problem.
-
@Chillax
qtquickapplicationviewer
was a helper class added back then which calls other in-built functions to load QML files. It also provided some extra functions for ease. You can also directly useQQuickView
orQQmlApplicationEngine
to load the QML files depending upon the root object. This is all Qt 5.x related.
Similarlyqmlapplicationviewer
is an helper class. If you look into its source you can see it is actually subclassed fromQDeclarativeView
which actually loads and displays the QML files.I'm not sure if the applicationviewer or the qt version difference causes my problem.
AFAIK definitely not
applicationviewer
but may be Qt version.Also did you try running same application with Qt 4.8 on desktop ? I think you should try that too to rule out the system problem if any.
-
@p3c0 So I spent the last couple of hours trying to find out how to install Qt version 4.8 on Ubuntu, but it turns out that only the versions newer than 5.0 support linux. So I installed Qt Creator and Qt version 4.8 on Windows and it works there as well :)
-
@p3c0 Interesting news: Until now, my
QmlApplicationViewer flowView
was just a new window on top of the GUI I was using until now. But if I show onlyflowView
in fullscreen and nothing else, it works (updates/repaints).qmlRegisterType<FlowGrafik>("FlowGrafik",1,0,"FlowGrafik"); QmlApplicationViewer flowView; flowView.setSource(QUrl("qrc:///qml/qml/FlowView.qml")); flowView.showFullScreen();
-
@p3c0 What's more interesting: If I call
addFlow
from QML, it works (replots). But if I call it from C++, it updates theQWidget
, but not the QML Item. Even if I callrefresh()
from QML right after it, which should replot and repaint the QML Item too. Any explanation to this? Why is there a difference between changing the QWidget in the C++ code and asking for a replot from QML and doing everything in QML? As if the QML Item and the C++ QDeclarativeItem were two independent objects.So now my plan is to give the flow value from C++ to the
FlowGrafik
QML item, and then calladdFlow
from QML. That should work. -
@Chillax Unfortunately I too dont understand this behavior. The fact that it works in desktop environment and not on embedded only points that there should be some bug in that environment.
So now my plan is to give the flow value from C++ to the FlowGrafik QML item, and then call addFlow from QML.
Try. I had suggested the same earlier :)
Let us know if it works or if possible the exact reason so that it may help others too. -
@p3c0 So thanks a lot for the help! I would have given up without you :) The problem was that I created two instances of
FlowGrafik
. One in the QML and one in C++. I changed the C++ one and expected the QML one to refresh.Now I created a pointer in the C++ code that points to the Item in the QML.
QmlApplicationViewer flowView; flowView.setSource(QUrl("qrc:///qml/qml/FlowView.qml")); QObject * flowViewObject = flowView.rootObject(); FlowGrafik * flowGrafik = flowViewObject->findChild<FlowGrafik *>(QString("FlowGrafik"));
But now if I want to use this pointer (like
flowGrafik->addFlow(...)
) I get a segmentation fault. Do you know why? -
@Chillax Thank you :)
The problem was that I created two instances of FlowGrafik. One in the QML and one in C++. I changed the C++ one and expected the QML one to refresh.
but now this makes me wonder as to why it worked on desktop.
But now if I want to use this pointer (like flowGrafik->addFlow(...)) I get a segmentation fault. Do you know why?
Was the
FlowGrafik
object found ? You can add a small condition to verify it.if(flowGrafik) { flowGrafik->addFlow(...) }