Problem with displaying Charts in qml project: MUTEX problem

30 Views Asked by At

I'am beginner in qml and I have this kind of problem. I wanted to display chart in qml and someone adviced me to change QGuiApplication to QApplication in main.cpp. It was working for a few hours, but now I have this problem:

QML debugging is enabled. Only use this in a safe environment.
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
QMutex: destroying locked mutex

Here's my main.qml code:

import QtQuick 2.9
import QtQuick.Window 2.12
import QtQuick.Controls 2.5
import QtQuick.Controls 1.4 as C1
import QtCharts 2.3

//załączone pozostałe pliki
import "."

ApplicationWindow {
    width: 800
    height: 480
    visible: true
    title: qsTr("Power Analizer")

    C1.TabView {
        id: tabview
        anchors.fill: parent

        C1.Tab{
            id: tab1
            title: "Moc"

            Rectangle{
                width: tab1.width
                height: tab1.height
                Image {
                    source: "zdj/tlo.jpg"
                    anchors.fill: parent
                }

                //lewa strona
                Rectangle {
                    color: "transparent"
                    anchors {
                        left: parent.left
                        top: parent.top
                    }
                    width: tab1.width /3
                    height: tab1.height
                    Image {

                        x: -34
                        y: 50
                        source: "zdj/amper.png"
                        width: 350
                        height: 350
                        Image{
                            id: wskazowka1_1
                            source: "zdj/needle-61.png"
                            width: 335
                            height: 335
                            anchors.centerIn: parent
                            rotation: suwak1_1.value
                        }
                    }

                    //suwak
                    Slider {
                        id: suwak1_1
                        width: 200
                        height: 50
                        from: 0
                        to: 120
                        stepSize: 0.1
                        anchors {
                            left: parent.left
                            leftMargin: 40
                            bottom: parent.bottom
                            bottomMargin: 30
                        }

                    }

                }


                //prawa strona
                Rectangle {
                    color: "transparent"
                    anchors {
                        right: parent.right
                        top: parent.top
                    }
                    width: tab1.width /3
                    height: tab1.height
                    Image {
                        x: -50
                        y: 50
                        source: "zdj/volt.png"
                        width: 350
                        height: 350
                        Image{
                            id: wskazowka1_3
                            source: "zdj/needle-63.png"
                            width: 350
                            height: 350
                            anchors.centerIn: parent
                            rotation: suwak1_3.value
                        }
                    }

                    //przycisk zamknięcia
                    Close {
                        text: "Zamknij"
                        onClicked: {
                        close()
                        }
                    }

                    //suwak
                    Slider {
                        id: suwak1_3
                        width: 200
                        height: 50
                        from: 0
                        to: 124
                        stepSize: 0.1
                        anchors {
                            left: parent.left
                            leftMargin: 40
                            bottom: parent.bottom
                            bottomMargin: 30
                        }

                    }

                }


                //środek
                Rectangle {
                    color: "transparent"
                    anchors {
                        centerIn: parent
                    }
                    width: tab1.width /3
                    height: tab1.height
                    Image {
                        anchors.centerIn: parent
                        source: "zdj/kWatt.png"
                        width: 550
                        height: 550
                        Image{
                            id: wskazowka1_2
                            source: "zdj/needle-63.png"
                            width: 550
                            height: 550
                            anchors.centerIn: parent
                            rotation: (suwak1_3.value === 0 || suwak1_1.value === 0) ? 0 : suwak1_1.value * suwak1_3.value/120
                        }
                    }
                }
            }
        }

        C1.Tab{
            id: tab2
            title: "Tab_2"

            ChartView {
                id: chart
                anchors.fill: parent
                theme: ChartView.ChartThemeBrownSand
                antialiasing: true

                SplineSeries {
                    name: "sin(x)"
                    XYPoint { x: 0; y: 1 }
                    XYPoint { x: 2; y: -1 }
                    XYPoint { x: 4; y: 1 }
                    XYPoint { x: 6; y: -1 }
                    XYPoint { x: 8; y: 1 }
                    XYPoint { x: 10; y: -1 }
                    XYPoint { x: 12; y: 1 }
                }
            }
        }

        C1.Tab{
            id: tab3
            title: "Tab_3"
            Rectangle{
                width: tab3.width
                height: tab3.height
                color: "green"
                Close {
                    text: "Zamknij"
                    onClicked: {
                    close()
                    }
                }
            }


        }
    }

}

Here's main.cpp:

#include <QApplication>
#include <QQmlApplicationEngine>
#include <QTimer>
#include <QtCharts/qchartview.h>

int main(int argc, char *argv[])
{
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif

    QApplication app(argc, argv);

    QQmlApplicationEngine engine;
    const QUrl url(QStringLiteral("qrc:/main.qml"));
    QObject::connect(&engine, &QQmlApplicationEngine::objectCreated,
        &app, [url](QObject *obj, const QUrl &objUrl) {
        if (!obj && url == objUrl)
            QCoreApplication::exit(-1);
    }, Qt::QueuedConnection);
    engine.load(url);

    return app.exec();
}

And a project.pro:

QT += quick \
    widgets

CONFIG += c++11
CONFIG += qml_debug

# You can make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0

SOURCES += \
    main.cpp

RESOURCES += qml.qrc

# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =

# Additional import path used to resolve QML modules just for Qt Quick Designer
QML_DESIGNER_IMPORT_PATH =

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target

DISTFILES +=

HEADERS +=

Could you tell me how to repair it?

0

There are 0 best solutions below