0

I am trying to use this source to create an oscilloscope view on my application. Here is the source i am using which is created by QT team

https://code.qt.io/cgit/qt/qtcharts.git/tree/examples/charts/qmloscilloscope?h=6.2

I have a lot of screens but i want to show this oscilloscope on my homepage with some other stuff. I already created ControlPanel.qml, ScopeView.qml and MultiButton.qml. Instead of main.qml in the project, i have created a qml named ChartTest.qml. Also carried the datasource.cpp and datasource.h to my project. When i initialize it with main.cpp below

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QTimeEdit>
#include <QString>
#include <QApplication>
#include "myclass.h"
#include <QQmlContext>
#include <stdio.h>
#include <stdlib.h>
#include <QSqlRecord>
#include "backend.h"
#include <QQmlContext>
#include <QQmlComponent>
#include <QQmlProperty>
#include <QCursor>
#include <QtWidgets/QApplication>
#include <QtQml/QQmlContext>
#include <QtQuick/QQuickView>
#include <QtQml/QQmlEngine>
#include <QtCore/QDir>
#include "datasource.h"




int main(int argc, char *argv[])
{



QApplication app(argc, argv);
QQmlApplicationEngine engine;

bool openGLSupported = QQuickWindow::graphicsApi() == QSGRendererInterface::OpenGLRhi;
if (!openGLSupported) {
    qWarning() << "OpenGL is not set as the graphics backend, so AbstractSeries.useOpenGL will not work.";
    qWarning() << "Set QSG_RHI_BACKEND=opengl environment variable to force the OpenGL backend to be used.";
}
QQuickView viewer;
#ifdef Q_OS_WIN
    QString extraImportPath(QStringLiteral("%1/../../../../%2"));
#else
    QString extraImportPath(QStringLiteral("%1/../../../%2"));
#endif
    viewer.engine()->addImportPath(extraImportPath.arg(QGuiApplication::applicationDirPath(),
                                      QString::fromLatin1("qml")));

QObject::connect(viewer.engine(), &QQmlEngine::quit, &viewer, &QWindow::close);
DataSource dataSource(&viewer);
viewer.rootContext()->setContextProperty("dataSource", &dataSource);
viewer.rootContext()->setContextProperty("openGLSupported", openGLSupported);
viewer.setSource(QUrl("qrc:/deneme/ChartTest.qml"));
viewer.setResizeMode(QQuickView::SizeRootObjectToView);
myclass KeyEmitter;
SerialPortHandler* sb = SerialPortHandler::getInstance();
DatabaseHandler* db = DatabaseHandler::getInstance();
BackEnd backend = BackEnd(sb,db);
engine.rootContext()->setContextProperty("keyEmitter",&KeyEmitter);
engine.rootContext()->setContextProperty("backendHandler", &backend);
QQmlContext* context = engine.rootContext();
context->setContextProperty("keyEmitter", &KeyEmitter);
const QUrl url(u"qrc:/deneme/main.qml"_qs);
QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
                 &app, [url](QObject *obj, const QUrl &objUrl) {
    if (!obj && url == objUrl)
        QCoreApplication::exit(-1);
}, Qt::QueuedConnection);
engine.load(url);
viewer.show();

return app.exec();


}

My application starts and works functionally, but viewer(which is oscilloscope QQuickView object) starts in another window. I tried to include it into my QApplication but couldn't handle that. I want to use that QQuickView in my QApplication as a content just like a normal chartview on some page.

Sorry about syntax, i have some backend and keyboard stuff in it. What i want to have is get something like this

enter image description here

instead of this

enter image description here

I read articles about it but none of them solved my problem because not relevant. Couldn't find any good practice.

how does qwt oscilloscope example's samplingthread class work in the project?

Push QML ChartView updates from c++

Qwt oscilloscope example combined with qextserialport

any ideas?

utkuyceng
  • 43
  • 6
  • Why are you using QQuickView? It looks like you're loading main.qml from a QQmlApplicationEngine. Just load ChartTest.qml from main.qml like any other QML file. – JarMan Jan 14 '23 at 15:35

0 Answers0