Hi,
I'm trying to display qml file with help of QQuickView running in separate thread. My platform is beaglebone (am33xx qt5.5 compiled by yocto project with opengl).
I debug problem a bit and only after disabling of line 523 (in qtbase/src/gui/kernel/sources/qwindow.cpp)
d->platformWindow->setVisible(visible);
it was possible to use showFullScreen() in QquickView. The other show() function still doesn't work (means that the execution of the program is frozen after this place in code). The showFullScreen() is working restricted, it can show simple qml file, but doesn't show animation. There are some warnings in log file like :
WARNING: QObject::moveToThread: Current thread (0x6ff08) is not the object's thread (0x112740). Cannot move to target thread (0x156560)
WARNING: Updates can only be scheduled from GUI thread or from QquickItem::updatePaintNode()
When don't use separate thread and put everything in main.cpp then everything works as expected (including animations). Any ideas what could be wrong in my implementation? Thanks.
main.cpp:
#include <iostream>
#include <QGuiApplication>
#include <QQuickView>
#include "mythread.h"
#include <qdebug.h>
using namespace std;
int main(int argc, char ** argv)
{
QGuiApplication app(argc, argv);
qDebug() << "app.thread() " << QGuiApplication::instance()->thread();
MyThread thread;
thread.start();
return app.exec();
}
#include <iostream>
#include <QGuiApplication>
#include <QQuickView>
#include "mythread.h"
#include <qdebug.h>
using namespace std;
int main(int argc, char ** argv)
{
QGuiApplication app(argc, argv);
qDebug() << "app.thread() " << QGuiApplication::instance()->thread();
MyThread thread;
thread.start();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
mythread.cpp:
#include "mythread.h"
#include <QDebug>
#include <QString>
#include <QMutexLocker>
#include <QTime>
MyThread::MyThread() {
m_view = new QQuickView();
engine = new QQmlApplicationEngine();
window = NULL;
}
void MyThread::run() {
qDebug() << "thread() " << currentThread();
m_view
->setSource
(QUrl(QStringLiteral
("qrc:/test/loadingView.qml")));
m_view->show();
exec();
}
void MyThread::setWindow(QQuickWindow* ptr) {
if (ptr)
window = ptr;
else {
window = new QQuickWindow();
}
}
#include "mythread.h"
#include <QDebug>
#include <QString>
#include <QMutexLocker>
#include <QTime>
MyThread::MyThread() {
m_view = new QQuickView();
engine = new QQmlApplicationEngine();
window = NULL;
}
void MyThread::run() {
qDebug() << "thread() " << currentThread();
m_view->setSource(QUrl(QStringLiteral("qrc:/test/loadingView.qml")));
m_view->show();
exec();
}
void MyThread::setWindow(QQuickWindow* ptr) {
if (ptr)
window = ptr;
else {
window = new QQuickWindow();
}
}
To copy to clipboard, switch view to plain text mode
mythread.h
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QThread>
#include <QMutex>
#include <QQuickView>
#include <QQmlApplicationEngine>
Q_OBJECT
public:
MyThread();
public slots:
void run();
void setWindow(QQuickWindow* ptr);
private:
QQmlApplicationEngine *engine;
QQuickWindow *window;
QQuickView *m_view;
};
#endif // MYTHREAD_H
#ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QThread>
#include <QMutex>
#include <QQuickView>
#include <QQmlApplicationEngine>
class MyThread : public QThread {
Q_OBJECT
public:
MyThread();
public slots:
void run();
void setWindow(QQuickWindow* ptr);
private:
QQmlApplicationEngine *engine;
QQuickWindow *window;
QQuickView *m_view;
QObject *topLevel;
};
#endif // MYTHREAD_H
To copy to clipboard, switch view to plain text mode
qml file:
import QtQuick 2.0
import QtQuick.Window 2.2
Window {
property var value: 0
property string colGreyVeryLight: "#cccccc"
property string colGreyLight: "#999999"
property string colGrey: "#444444"
property string colGreyDark: "#262a2b"
property var timerIntervalTime: 250
id: screen
width: 800
height: 480
color: "black"
objectName: "list"
MouseArea {
id: mouseArea
width: 480
height: 360
anchors.rightMargin: 0
anchors.bottomMargin: -497
anchors.leftMargin: 8
anchors.topMargin: 497
anchors.fill: parent
}
Text {
id: loadingText
x: 300
y: 67
width: 180
height: 30
color: "#ffffff"
text: qsTr("Loading...")
font.bold: true
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 14
font.pixelSize: 14
}
Timer {
interval: timerIntervalTime; running: true; repeat: true
onTriggered: (value == 4) ? value = 0 : value++
}
Rectangle {
id: rect1
x: 65
y: 192
width: 50
height: 50
color: (value == 0) ? colGreyVeryLight : ((value == 1) ? colGreyLight : (value == 2) ? colGrey : colGreyDark)
}
Rectangle {
id: rect2
x: 203
y: 192
width: 50
height: 50
color: (value == 1) ? colGreyVeryLight : ((value == 2) ? colGreyLight : (value == 3) ? colGrey : colGreyDark)
}
Rectangle {
id: rect3
x: 354
y: 192
width: 50
height: 50
color: (value == 2) ? colGreyVeryLight : ((value == 3) ? colGreyLight : (value == 4) ? colGrey : colGreyDark)
}
Rectangle {
id: rect4
x: 511
y: 192
width: 50
height: 50
color: (value == 3 ) ? colGreyVeryLight : ((value == 4) ? colGreyLight : colGreyDark)
}
Rectangle {
id: rect5
x: 674
y: 192
width: 50
height: 50
color: (value == 4 ) ? colGreyVeryLight : colGreyDark
}
}
import QtQuick 2.0
import QtQuick.Window 2.2
Window {
property var value: 0
property string colGreyVeryLight: "#cccccc"
property string colGreyLight: "#999999"
property string colGrey: "#444444"
property string colGreyDark: "#262a2b"
property var timerIntervalTime: 250
id: screen
width: 800
height: 480
color: "black"
objectName: "list"
MouseArea {
id: mouseArea
width: 480
height: 360
anchors.rightMargin: 0
anchors.bottomMargin: -497
anchors.leftMargin: 8
anchors.topMargin: 497
anchors.fill: parent
}
Text {
id: loadingText
x: 300
y: 67
width: 180
height: 30
color: "#ffffff"
text: qsTr("Loading...")
font.bold: true
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
font.pointSize: 14
font.pixelSize: 14
}
Timer {
interval: timerIntervalTime; running: true; repeat: true
onTriggered: (value == 4) ? value = 0 : value++
}
Rectangle {
id: rect1
x: 65
y: 192
width: 50
height: 50
color: (value == 0) ? colGreyVeryLight : ((value == 1) ? colGreyLight : (value == 2) ? colGrey : colGreyDark)
}
Rectangle {
id: rect2
x: 203
y: 192
width: 50
height: 50
color: (value == 1) ? colGreyVeryLight : ((value == 2) ? colGreyLight : (value == 3) ? colGrey : colGreyDark)
}
Rectangle {
id: rect3
x: 354
y: 192
width: 50
height: 50
color: (value == 2) ? colGreyVeryLight : ((value == 3) ? colGreyLight : (value == 4) ? colGrey : colGreyDark)
}
Rectangle {
id: rect4
x: 511
y: 192
width: 50
height: 50
color: (value == 3 ) ? colGreyVeryLight : ((value == 4) ? colGreyLight : colGreyDark)
}
Rectangle {
id: rect5
x: 674
y: 192
width: 50
height: 50
color: (value == 4 ) ? colGreyVeryLight : colGreyDark
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks