Attaching full source (qml remains unchanged):
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
mytheread.cpp
#include "mythread.h"
#include <QDebug>
#include <QString>
#include <QMutexLocker>
#include <QTime>
MyThread::MyThread() {
m_view = new QQuickView();
connect(this, SIGNAL(show()), m_view, SLOT(show()));
connect(this,
SIGNAL(qmlSetSource
(QUrl)), m_view,
SLOT(setSource
(QUrl)));
}
void MyThread::run() {
qDebug() << "thread() " << currentThread();
emit qmlSetSource
(QUrl(QStringLiteral
("qrc:/test/loadingView.qml")));
emit show();
exec();
}
#include "mythread.h"
#include <QDebug>
#include <QString>
#include <QMutexLocker>
#include <QTime>
MyThread::MyThread() {
m_view = new QQuickView();
connect(this, SIGNAL(show()), m_view, SLOT(show()));
connect(this, SIGNAL(qmlSetSource(QUrl)), m_view, SLOT(setSource(QUrl)));
}
void MyThread::run() {
qDebug() << "thread() " << currentThread();
emit qmlSetSource(QUrl(QStringLiteral("qrc:/test/loadingView.qml")));
emit show();
exec();
}
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();
private:
QQuickView *m_view;
signals:
void show();
void qmlSetSource
(QUrl url
);
};
#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();
private:
QQuickView *m_view;
signals:
void show();
void qmlSetSource(QUrl url);
};
#endif // MYTHREAD_H
To copy to clipboard, switch view to plain text mode
Bookmarks