Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Plotting in new window
Forum Updated to NodeBB v4.3 + New Features

Plotting in new window

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 1.1k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    MScottM
    wrote on 20 Jan 2018, 19:39 last edited by
    #1

    Hi All,

    So my project, which reads a text log file and plots the data on the mainWindow using QCustomPlot has been working well, so in the interest of continuing to learn (onwards and upwards!), I decided that I wanted my graph to be in a new separate window and have most of the functionality that is demonstrated in the QCustomPlot example 'interactions' (clickable, zoomable, etc). I have created a new QDialog form called graphWindowDialog.ui, with graphWindowDialog.cpp, and graphWindowDialog.h. In my mainWindow.cpp I changed my function that populated the graph widget, to now send a signal to a slot in graphWindowDialog.cpp.

    When I run it, the window will appear and there is a graph squished up in the corner of the window. I think this is because my signal is not sending over the data correctly...?

    Here is my code (snipped for brevity):

    in MainWindow.cpp:

    /********************* populate the graph ***********************/
    void MainWindow::graphSelected(QStringList _graphingData, QString sensorName) {
    
        graphWindowDialog = new GraphWindowDialog(this);
        graphWindowDialog->show();
        connect(ui->btnChartData, SIGNAL(clicked()), this, SLOT(redirectData));
                connect(this, SIGNAL(redirectData(_graphingData, sensorName)), graphWindowDialog, SLOT(addGraph(QStringList, QString)));
       
    }
    

    in MainWindow.h:

    signals:
        void redirectData(QStringList _graphingData, QString sensorName);
    
    
    private slots:
        void handleFileButton();
        void on_btnChartData_clicked();
        void on_btnClearChart_clicked();
        void graphSelected(QStringList, QString);
        //void addGraph(QStringList, QString);
    
    private:
        Ui::MainWindow *ui;
        GraphWindowDialog *graphWindowDialog;
        QPushButton *m_button;
        //QCustomPlot *customPlot;
    };
    

    in graphWindowDialog.cpp:

    void GraphWindowDialog::addGraph(QStringList _graphingData, QString sensorName)
    {
    
            QList<QStringList> list;
            QList<double> dataPoints;
            foreach (const QString &s, _graphingData) {
                const QStringList parts = s.split(",");
                list.append(parts);
                Q_ASSERT(parts.size() >= 3);
                dataPoints.append(parts.at(2).toDouble());
            }
    
            QVector<double> y = QVector<double>::fromList(dataPoints);
    
            if (Debug) {
            qDebug() << list;
            qDebug() << dataPoints;
            }
    
            int j = dataPoints.size();
            QVector<double> x(j);
    
            for (int i=0; i<j; i++) {
                x[i]=i;
            }
    
    customPlot->graph()->setName(QString(sensorName).arg(customPlot->graphCount()-1));
      customPlot->graph()->setData(x, y);
      customPlot->graph()->setLineStyle((QCPGraph::LineStyle)(rand()%5+1));
      if (rand()%100 > 50)
        customPlot->graph()->setScatterStyle(QCPScatterStyle((QCPScatterStyle::ScatterShape)(rand()%14+1)));
      QPen graphPen;
      graphPen.setColor(QColor(rand()%245+10, rand()%245+10, rand()%245+10));
      graphPen.setWidthF(rand()/(double)RAND_MAX*2+1);
      customPlot->graph()->setPen(graphPen);
      customPlot->adjustSize();
      customPlot->replot();
    }
    

    and graphWindowDialog.h:

    public:
        explicit GraphWindowDialog(QWidget *parent = 0);
        ~GraphWindowDialog();
        bool Debug;
    
    private slots:
        void addGraph(QStringList _graphingData, QString sensorName);
    
    private:
          Ui::GraphWindowDialog *ui;
          QCustomPlot *customPlot;
          void titleDoubleClick(QMouseEvent *event);
          void axisLabelDoubleClick(QCPAxis* axis, QCPAxis::SelectablePart part);
          void legendDoubleClick(QCPLegend* legend, QCPAbstractLegendItem* item);
          void selectionChanged();
          void mousePress();
          void mouseWheel();
          void addGraph();
          void removeSelectedGraph();
          void removeAllGraphs();
          void contextMenuRequest(QPoint pos);
          void moveLegend();
          //void graphClicked(QCPAbstractPlottable *plottable, int dataIndex);
    };
    

    When I run it I also get these runtime messages:

    QObject::connect: No such slot GraphWindowDialog::selectionChanged() in ..\NewLogReader\graphwindowdialog.cpp:37
    QObject::connect:  (receiver name: 'GraphWindowDialog')
    QObject::connect: No such slot GraphWindowDialog::mousePress() in ..\NewLogReader\graphwindowdialog.cpp:39
    QObject::connect:  (receiver name: 'GraphWindowDialog')
    QObject::connect: No such slot GraphWindowDialog::mouseWheel() in ..\NewLogReader\graphwindowdialog.cpp:40
    QObject::connect:  (receiver name: 'GraphWindowDialog')
    QObject::connect: No such slot GraphWindowDialog::axisLabelDoubleClick(QCPAxis*,QCPAxis::SelectablePart) in ..\NewLogReader\graphwindowdialog.cpp:47
    QObject::connect:  (receiver name: 'GraphWindowDialog')
    QObject::connect: No such slot GraphWindowDialog::legendDoubleClick(QCPLegend*,QCPAbstractLegendItem*) in ..\NewLogReader\graphwindowdialog.cpp:48
    QObject::connect:  (receiver name: 'GraphWindowDialog')
    QObject::connect: No such slot GraphWindowDialog::titleDoubleClick(QMouseEvent*) in ..\NewLogReader\graphwindowdialog.cpp:49
    QObject::connect:  (receiver name: 'GraphWindowDialog')
    QObject::connect: No such slot GraphWindowDialog::graphClicked(QCPAbstractPlottable*,int) in ..\NewLogReader\graphwindowdialog.cpp:52
    QObject::connect:  (receiver name: 'GraphWindowDialog')
    QObject::connect: No such slot GraphWindowDialog::contextMenuRequest(QPoint) in ..\NewLogReader\graphwindowdialog.cpp:56
    QObject::connect:  (receiver name: 'GraphWindowDialog')
    QObject::connect: Parentheses expected, slot MainWindow::redirectData in ..\NewLogReader\mainwindow.cpp:104
    QObject::connect:  (sender name:   'btnChartData')
    QObject::connect:  (receiver name: 'MainWindow')
    QObject::connect: No such signal MainWindow::redirectData(_graphingData, sensorName) in ..\NewLogReader\mainwindow.cpp:105
    QObject::connect:  (sender name:   'MainWindow')
    QObject::connect:  (receiver name: 'GraphWindowDialog')
    

    By the way, this is the first time I have really tried to use signals and slots...
    thanks for any hints!!

    -scott

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 20 Jan 2018, 20:28 last edited by
      #2

      Hi,

      Don't pass parameters in the connect statement. That's not how it works. You should also consider using the new syntax using function pointers. That will avoid that kind of mistake.

      See the Signals & Slots chapter of Qt's documentation for more information.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1

      1/2

      20 Jan 2018, 19:39

      • Login

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