Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. how to transferred QLineSeries from c++ to qml
Forum Updated to NodeBB v4.3 + New Features

how to transferred QLineSeries from c++ to qml

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 131 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wallace Stevens
    wrote on last edited by
    #1

    version 6.8
    I pass the c++ QLinSeries into qml through signals and slots,Slot functions trigger normally,but the lineSeries parameter of the qml addSeries function is empty; it has no properties.

    I read this document.Once a class is registered as a QML type, it can be used as a data type for exchanging data between QML and C++. Isn't QLineSeries already registered with the qml type? Its type in qml is LineSeries.

    cpp

    #pragma once
    #include <QObject>
    #include <QLineSeries>
    
    class MainWindowViewModel : public QObject
    {
        Q_OBJECT
    public:
        void addSeries(QLineSeries *data);
    signals:
        void seriesAdded(QLineSeries *data);
    };
    

    main.cpp

        QList<QPointF> dataList;
        ...
        QLineSeries *lineSeries = new QLineSeries();
        lineSeries->append(dataList);
        lineSeries->setColor(QColor("black"));
    
        QQmlApplicationEngine engine;
    
        MainWindowViewModel *viewModel = new MainWindowViewModel();
    
        engine.loadFromModule("chromChart", "MainWindow");
    
        QObject::connect(viewModel, SIGNAL(seriesAdded(QLineSeries *)), engine.rootObjects()[0], SLOT(addSeries(QLineSeries *)));
    //emit signals
        viewModel->addSeries(lineSeries);
    

    qml

        function addSeries(lineSeries: LineSeries) {
            try {
                console.log("trigger slot function")
                graphsView.addSeries(lineSeries);
    
                for (var prop in lineSeries) {
                    console.log("Object item:", prop, "=", lineSeries[prop]);
                }
    
            } catch (e) {
                console.log(e);
            }
        }
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved