Hi,
I have a QuickView interface where the user can edit data.
A reset button (inside the interface) sets the underlying data (an interface object that is set as a context property) back to model data by calling a slot in that very interface object. Unfortunately, the qml content is not being visibly updated.
I'd be happy with just rebuilding the QML content from scratch by setting the QQuickview's source anew after resetting my data, like here:
void ControllerClass::redrawIncEditView()
{
Q_ASSERT(m_quickView);
auto url = m_quickView->source();
// m_quickView->hide();
m_quickView->setSource(url); //<<<<< HERE we have the assert you see below
// m_quickView->show();
}
void ControllerClass::redrawIncEditView()
{
Q_ASSERT(m_quickView);
auto url = m_quickView->source();
// m_quickView->hide();
m_quickView->setSource(url); //<<<<< HERE we have the assert you see below
// m_quickView->show();
}
To copy to clipboard, switch view to plain text mode
But calling this leads to a crash in Qt:
ASSERT: "context() && engine()" in file qml\qqmlboundsignal.cpp, line 183
I have no idea why the crash occurs. Ive seen very similar / same error messages on Google, but in quite different contexts, as far as I can see.
I've also tried calling the following methods of QQuickView, but they don't show any effect (probably they just cover the graphical aspects):
m_quickView->update();
m_quickView->requestUpdate();
m_quickView->renderTarget();
m_quickView->update();
m_quickView->requestUpdate();
m_quickView->renderTarget();
To copy to clipboard, switch view to plain text mode
Interesting update:
The above approach works when started by a single shot timer. Therefore I have to subclass QQuickView, adding a "redraw"-method that takes no argument (to make it usable with QTimer::singleShot):
class MyQQuickView: public QQuickView {
Q_OBJECT
public slots:
void redraw() { this->setSource(this->source()); }
};
class MyQQuickView: public QQuickView {
Q_OBJECT
public slots:
void redraw() { this->setSource(this->source()); }
};
To copy to clipboard, switch view to plain text mode
and call that in this way:
void ControllerClass::redrawIncEditView()
{
Q_ASSERT(m_quickView);
QTimer::singleShot(1,m_quickView,
SLOT(redraw
()));
}
void ControllerClass::redrawIncEditView()
{
Q_ASSERT(m_quickView);
QTimer::singleShot(1,m_quickView,SLOT(redraw()));
}
To copy to clipboard, switch view to plain text mode
Any idea about what is behind the crash? Is it a threading problem?
Are there better / more elegant ways to force a QML redraw?
Is that hack somewhat safe in the first place? I can use it with 1 ms here - but could this be different on a phone?
Bookmarks