QtCharts::QLineSeries(0x2ea7560, There is no data on chart
Unsolved
General and Desktop
-
It isnt add queue datas into chart, error says QtCharts::QLineSeries(0x2ea7560)
Where is my mistake?
mainwindow.cpp#include "mainwindow.h" #include "ui_mainwindow.h" #include <QtCore> #include <QMainWindow> #include <QtWidgets/QMainWindow> #include <QtCharts> #include <QChart> QT_CHARTS_USE_NAMESPACE using namespace QtCharts; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { ui->setupUi(this); initChartView(); connect(m_timer, SIGNAL(timeout()), SLOT(Timer_Slot())); m_timer->setInterval(500); m_timer->start(); myThreadObject = new mythread(); myQThread = new QThread(); myThreadObject->moveToThread(myQThread); connect(this, &MainWindow::startWriting, myThreadObject, &mythread::writeData); connect(myThreadObject, &mythread::writingDone, this, &MainWindow::writingDoneByThread); connect(myThreadObject, &mythread::mysignal, this, &MainWindow::myslot); // Start the new thread myQThread->start(); } MainWindow::~MainWindow() { delete ui; } void MainWindow::Timer_Slot() { static float q_x; if(!queue.isEmpty()) { double num=queue.dequeue(); q_x += 0.1; series->append(q_x, num); qDebug() << "this is qx " << q_x; qDebug() << "this is num " << num; chart->update(); } } void MainWindow::initChartView() { QChart *chart = new QChart(); chart->ChartTypeCartesian; chart->addSeries(series); qDebug()<< series; QPen green(Qt::red); green.setWidth(2); series->setPen(green); chart->legend()->hide(); chart->setTitle("deneme"); chart->setAnimationOptions(QChart::AllAnimations); QValueAxis *axisX=new QValueAxis; axisX->setTickCount(10); axisX->setRange(0,5); axisX->applyNiceNumbers(); chart->addAxis(axisX, Qt::AlignBottom); series->attachAxis(axisX); QValueAxis *axisY = new QValueAxis; axisY->setTickCount(10); axisY->setRange(0, 5); axisY->applyNiceNumbers(); chart->addAxis(axisY, Qt::AlignLeft); series->attachAxis(axisY); QChartView *chartView = new QChartView(chart); chartView->setRenderHint(QPainter::Antialiasing); this->setCentralWidget(chartView); }
mainwindow.h
#include <QLineSeries> QT_CHARTS_USE_NAMESPACE QT_BEGIN_NAMESPACE namespace Ui { class MainWindow; } QT_END_NAMESPACE class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(QWidget *parent = Q_NULLPTR); ~MainWindow(); void initChartView(); private: Ui::MainWindow *ui; mythread* myThreadObject; //mythreadden yeni bir obje yaratıyorum QThread* myQThread; //QThreadden bir obje yaratıyorum QChart *chart = new QChart(); QLineSeries *series = new QLineSeries(); QQueue<double> queue; QTimer *m_timer = new QTimer(); signals: void startWriting(); public slots: void writingDoneByThread(); void myslot( QQueue<double>queue ); private slots: void Timer_Slot(); }; #endif // MAINWINDOW_H ```![0e547d28-f395-49f1-a5d0-17fddb2a2994-image.png](https://ddgobkiprc33d.cloudfront.net/8aa80dba-7f9d-41aa-9616-c709610d8c52.png)
-
@suslucoder Did you debug your app to find out whether your queue is actually filled with data?! Or do you want us to debug your code?
-
Hi
I cant see what you do in myslot ? -
@suslucoder said in QtCharts::QLineSeries(0x2ea7560, There is no data on chart:
error says QtCharts::QLineSeries(0x2ea7560)
What "error"?
qDebug()<< series;
Maybe
QtCharts::QLineSeries(0x2ea7560)
is what that prints when you ask it to print aQLineSeries *
? Since it is a pointer, maybe you intended to goqDebug()<< *series;
?