<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[QT Signals And Slots Between 2 Classes]]></title><description><![CDATA[<p dir="auto">From what I've understood, I should be very close in my code. I've got two separate Q_OBJECT objects housed under my main  program class, but when it comes time to connect the Signal to the Slot I run into an issue.</p>
<p dir="auto">The UIGraph object has a button, Recalculate, which when clicked will emit the signal CreateNewRun. I want this to trigger a function in the PID object which will execute some code.</p>
<p dir="auto">Optimally, I'll have the PID object then emit a signal afterwards to tell the UI to update based on the code available or pass a reference through the signal of the new code to be plotted. I feel like I'm missing something simple here. Any thoughts?</p>
<p dir="auto">Code below:</p>
<p dir="auto">mainwindow.cpp</p>
<pre><code>MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
    ui-&gt;setupUi(this);

    // UI Component
    graph = new UIGraph(this);
    QWidget* graphObject = graph-&gt;SetupUI();

    // PID Component
    pid = new PIDFunction();
    // Neither of these successfully resolve
    connect(&amp;graph, SIGNAL(CreateNewRun()), this-&gt;pid, SLOT(GenerateNewRun()));
    connect(&amp;graph, &amp;UIGraph::CreateNewRun, &amp;pid, &amp;PIDFunction::GenerateNewRun);

    setCentralWidget(graphObject);
}
</code></pre>
<p dir="auto">mainwindow.h</p>
<pre><code>#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include &lt;QMainWindow&gt;
#include "UI/uigraph.h"
#include "PID/pidfunction.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private:
    Ui::MainWindow *ui;
    UIGraph *graph;
    PIDFunction *pid;
};
#endif // MAINWINDOW_H
</code></pre>
<p dir="auto">UIGraph.h</p>
<pre><code>#ifndef UIGRAPH_H
#define UIGRAPH_H

#include &lt;QWidget&gt;
#include &lt;QMainWindow&gt;
#include &lt;QGroupBox&gt;
#include &lt;QLabel&gt;
#include &lt;QLineEdit&gt;
#include &lt;QPushButton&gt;
#include &lt;QVBoxLayout&gt;
#include &lt;QComboBox&gt;
#include "qcustomplot.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

enum TextIndications{
    ProprtionalGain,
    IntegralGain,
    DerivativeGain,
    LoopInterval,
    TargetValue,
    Period,
    Recalculate
};

class UIGraph : public QWidget
{
    Q_OBJECT
public:
    UIGraph(QWidget *parent = nullptr);
    void GenerateNewData();
    QWidget* SetupUI();

signals:
    void CreateNewRun();

private:
    Ui::MainWindow *ui;
    void PlotSetup();
    void SetupControlColumn();
    void PressRecalculateButton();

    QGroupBox *gridGroupBox;
    QLabel *labels[6];
    QLineEdit *lineEdits[6];
    QPushButton *recalculate;
    QVBoxLayout *mainLayout;
    QGridLayout *layout;
    QCustomPlot *customPlot;
    QComboBox *signalStyle;
    QWidget *body;

//private slots:
//    void GenerateNewGraph();

signals:

};

#endif // UIGRAPH_H
</code></pre>
<p dir="auto">pidfunction.h</p>
<pre><code>#ifndef PIDFUNCTION_H
#define PIDFUNCTION_H

#include "functiongenerator.h"
#include &lt;QObject&gt;

enum FunctionType {_line, _sin, _saw, _triangle, _square, _curvTriCave, _curTriVex };

class PIDFunction : public FunctionGenerator, public QObject
{
    Q_OBJECT

public:
    PIDFunction();
    void GenerateNextPoint();
    QVector&lt;double&gt; yOutput;
    void Process(double val);
    double Calculate(double setpoint, double pv);

    void SetP(double p);
    void SetI(double i);
    void SetD(double d);
    void SetLoopInterval(int _dt);
    void SetTargetValue(double t);
    //void SetPeriod(int p);

    void SetWaveform(int);

    void Reset();

public slots:
    void GenerateNewRun();

private:
    // proportional, integral, derivative
    double kp, ki, kd;
    // loop interval time
    double dt;
    // Min/Max of manipulated variable
    double max, min;
    // integral
    double integral;
    // Previous Error
    double pre_error = 0;
    // Stored Error
    double storedError = 0;
    // Target Value
    double target = 0;
    // Period
    int period = 10;

    double previousError;

    FunctionType ft;
};

#endif // PIDFUNCTION_H
</code></pre>
]]></description><link>https://forum.qt.io/topic/129915/qt-signals-and-slots-between-2-classes</link><generator>RSS for Node</generator><lastBuildDate>Wed, 19 Aug 2026 10:08:58 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/129915.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 31 Aug 2021 14:26:24 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to QT Signals And Slots Between 2 Classes on Tue, 31 Aug 2021 14:54:53 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jpatrick">@<bdi>JPatrick</bdi></a><br />
You were close, for a noob you did well on your own, you should see some of the questions we get! :)  Like I said, do yourself a favour and stick to that new style <code>connect()</code> syntax, then you get compile-time incompatibility error messages, look at those closely and you should be able to discern the cause.</p>
]]></description><link>https://forum.qt.io/post/678608</link><guid isPermaLink="true">https://forum.qt.io/post/678608</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 31 Aug 2021 14:54:53 GMT</pubDate></item><item><title><![CDATA[Reply to QT Signals And Slots Between 2 Classes on Tue, 31 Aug 2021 14:47:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jonb">@<bdi>JonB</bdi></a> and <a class="plugin-mentions-user plugin-mentions-a" href="/user/kromignon">@<bdi>KroMignon</bdi></a></p>
<p dir="auto">Good grief I feel like a fool.</p>
<pre><code>connect(graph, &amp;UIGraph::CreateNewRun, pid, &amp;PIDFunction::GenerateNewRun);
</code></pre>
<p dir="auto">worked without issue, and now I'm running again. Thank you for pointing out the obvious to me.</p>
]]></description><link>https://forum.qt.io/post/678605</link><guid isPermaLink="true">https://forum.qt.io/post/678605</guid><dc:creator><![CDATA[JPatrick]]></dc:creator><pubDate>Tue, 31 Aug 2021 14:47:39 GMT</pubDate></item><item><title><![CDATA[Reply to QT Signals And Slots Between 2 Classes on Tue, 31 Aug 2021 14:39:46 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jpatrick">@<bdi>JPatrick</bdi></a> said in <a href="/post/678594">QT Signals And Slots Between 2 Classes</a>:</p>
<blockquote>
<pre><code>// UI Component
graph = new UIGraph(this);
QWidget* graphObject = graph-&gt;SetupUI();

// PID Component
pid = new PIDFunction();
// Neither of these successfully resolve
connect(&amp;graph, SIGNAL(CreateNewRun()), this-&gt;pid, SLOT(GenerateNewRun()));
connect(&amp;graph, &amp;UIGraph::CreateNewRun, &amp;pid, &amp;PIDFunction::GenerateNewRun);
</code></pre>
</blockquote>
<p dir="auto">No this cannot work, <code>connect()</code> sender and receiver should be pointers not pointer of pointer!</p>
<pre><code>// Old syntax
connect(graph, SIGNAL(CreateNewRun()), pid, SLOT(GenerateNewRun()));
// new syntax
connect(graph, &amp;UIGraph::CreateNewRun, pid, &amp;PIDFunction::GenerateNewRun);

</code></pre>
]]></description><link>https://forum.qt.io/post/678602</link><guid isPermaLink="true">https://forum.qt.io/post/678602</guid><dc:creator><![CDATA[KroMignon]]></dc:creator><pubDate>Tue, 31 Aug 2021 14:39:46 GMT</pubDate></item><item><title><![CDATA[Reply to QT Signals And Slots Between 2 Classes on Tue, 31 Aug 2021 14:35:16 GMT]]></title><description><![CDATA[<p dir="auto">Was this connect really there when I read it the first time? Strange...<br />
Take a look at <a href="https://doc.qt.io/qt-5/signalsandslots.html" target="_blank" rel="noopener noreferrer nofollow ugc">https://doc.qt.io/qt-5/signalsandslots.html</a></p>
]]></description><link>https://forum.qt.io/post/678601</link><guid isPermaLink="true">https://forum.qt.io/post/678601</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Tue, 31 Aug 2021 14:35:16 GMT</pubDate></item><item><title><![CDATA[Reply to QT Signals And Slots Between 2 Classes on Tue, 31 Aug 2021 14:36:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jpatrick">@<bdi>JPatrick</bdi></a> said in <a href="/post/678594">QT Signals And Slots Between 2 Classes</a>:</p>
<blockquote>
<pre><code>// Neither of these successfully resolve
connect(&amp;graph, SIGNAL(CreateNewRun()), this-&gt;pid, SLOT(GenerateNewRun()));
connect(&amp;graph, &amp;UIGraph::CreateNewRun, &amp;pid, &amp;PIDFunction::GenerateNewRun);
</code></pre>
</blockquote>
<p dir="auto">Hi and welcome.</p>
<p dir="auto">If you showed/looked at the error message you would get further.</p>
<p dir="auto">Get rid of the <code>SIGNAL</code>/<code>SLOT()</code> macros approach and stick to the second case new style for all your work.  There the error message should be telling you (read it carefully!) what is wrong with your parameter types.  (Hint: <code>&amp;graph</code> and <code>&amp;pid</code> are wrong, you're almost there but over-complicating....)</p>
]]></description><link>https://forum.qt.io/post/678600</link><guid isPermaLink="true">https://forum.qt.io/post/678600</guid><dc:creator><![CDATA[JonB]]></dc:creator><pubDate>Tue, 31 Aug 2021 14:36:20 GMT</pubDate></item><item><title><![CDATA[Reply to QT Signals And Slots Between 2 Classes on Tue, 31 Aug 2021 14:31:53 GMT]]></title><description><![CDATA[<p dir="auto">Conect the signal and slot where you have access to both classes.</p>
]]></description><link>https://forum.qt.io/post/678597</link><guid isPermaLink="true">https://forum.qt.io/post/678597</guid><dc:creator><![CDATA[Christian Ehrlicher]]></dc:creator><pubDate>Tue, 31 Aug 2021 14:31:53 GMT</pubDate></item></channel></rss>