<?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[Design pattern of inventory management desktop application]]></title><description><![CDATA[<p dir="auto">Hi.<br />
I am new in software development and I want to ask for your advice regarding the right design pattern and common approach  for my project in Qt.<br />
I'll try to keep everything simple in the question.<br />
I am making an inventory management desktop application. I decided that the software should work as following:<br />
There is a main window with a button <em>get_btn</em>, that when the user clicks, a label from the main window is updated and filled with data received from database.<br />
So far I made a class <strong>clientAPI</strong> which is responsible for handling HTTP requests.<br />
there is a web api written in fastapi - python.</p>
<p dir="auto">The current design pattern is as follows:<br />
inside the <strong>clientAPI</strong> class, we have a function <em>get_item</em> which sends http get request.<br />
when the responses is received, there is a signal from <strong>clinetAPI</strong>  named <em>signal_data</em>  emitting the data.<br />
inside the <strong>mainWindow</strong> class we have the following:<br />
we have a pointer of <strong>clientAPI</strong> named <em>client</em> as private member function in the <strong>mainWindow</strong> class. We have also a button <em>get_btn</em>, and a <em>label</em> as private member functions.<br />
within the constructor of the <strong>mainWindow</strong>, we have two signal and slot connections. one connecting the <em>clicked</em> signal of <em>get_btn</em> to <em>get_item</em> function of <em>client</em> member function pointer.<br />
In the other connection the signal <em>signal_data</em> from <em>clinet</em> is connected to the <em>update_label</em> slot of <em>mainWindow</em>.</p>
<p dir="auto">My question is that if this design pattern is the common or right approach?<br />
(note that in this design pattern I have <em>clinet</em> as a pointer inside the mainWindow class as the member function)<br />
Should the design pattern be in different way. For example to have these two signal and slot connections in the main.cpp file and not inside the mainWindow.cpp. In other word, rather than having a <em>client</em> pointer as member function of the <strong>mainWindow</strong>, I make the two signal and slot connections inside the main.cpp.</p>
<p dir="auto">Below I provide the code of clientAPI class which is common across the two appraoches and the code of two appraoches.</p>
<p dir="auto">clientapi.cpp code:</p>
<pre><code>#include "clientapi.h"

clientAPI::clientAPI(QObject *parent): QObject{parent}
{
    manager = new QNetworkAccessManager(this);
    QObject::connect(
        manager,
        &amp;QNetworkAccessManager::finished,
        this,
        &amp;clientAPI::reply_finished);
}

clientAPI::~clientAPI()
{
    delete(manager);
    qInfo() &lt;&lt; "manager pointer was deleted.";
    qInfo() &lt;&lt; this &lt;&lt; "deconstructed";
}

void clientAPI::get_items()
{
    manager-&gt;get(QNetworkRequest(QUrl("http://127.0.0.1:8000/items/")));
    qInfo() &lt;&lt; "get request was sent";
}

void clientAPI::reply_finished(QNetworkReply* _reply)
{
    QByteArray responses = _reply-&gt;readAll();
    QJsonDocument JsonDoc = QJsonDocument::fromJson(responses);
    QJsonArray JsonArray = JsonDoc.array();
    QString data = JsonArray.at(1)["title"].toString();
    emit data_received(data);
    _reply-&gt;deleteLater();
}
</code></pre>
<p dir="auto"><strong>appraoch one</strong> :</p>
<p dir="auto">code of MainWindow.cpp</p>
<pre><code>#include "mainwindow.h"

MainWindow::MainWindow(clientAPI *_client, QWidget *parent): QMainWindow(parent), client(_client)
{
    get_btn = new QPushButton(this);
    test_label = new QLabel(this);

    get_btn-&gt;setGeometry(200,150, 80,40);
    get_btn-&gt;setText("register");

    test_label-&gt;setGeometry(300,150, 80,40);
    test_label-&gt;setText("...");
    test_label-&gt;setFrameStyle(QFrame::WinPanel | QFrame::Plain);

    //should I use test_label instead of this?!! &amp;&amp; what is private slots, is public better.
    connect(get_btn, &amp;QPushButton::clicked, client, &amp;clientAPI::get_items);
    connect(client, &amp;clientAPI::data_received, this, &amp;MainWindow::update_label);

}

MainWindow::~MainWindow() = default;

void MainWindow::update_label(const QString _data)
{
    test_label-&gt;setText(_data);
}
</code></pre>
<p dir="auto">main.cpp in appraoch 1 is :</p>
<pre><code>int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    clientAPI* client = new clientAPI();

    MainWindow w(client);
    w.show();
    return a.exec();
}
</code></pre>
<p dir="auto">In <strong>appraoch 2</strong>, the MainWindow is as follow:</p>
<pre><code>#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{
    get_btn = new QPushButton(this);
    test_label = new QLabel(this);

    get_btn-&gt;setGeometry(200,150, 80,40);
    get_btn-&gt;setText("register");

    test_label-&gt;setGeometry(300,150, 80,40);
    test_label-&gt;setText("...");
    test_label-&gt;setFrameStyle(QFrame::WinPanel | QFrame::Plain);

}

MainWindow::~MainWindow() = default;

void MainWindow::update_label(const QString _data)
{
    test_label-&gt;setText(_data);
}

QLabel *MainWindow::getTest_label() const
{
    return test_label;
}

void MainWindow::setTest_label(QLabel *newTest_label)
{
    test_label = newTest_label;
}

QPushButton *MainWindow::getGet_btn() const
{
    return get_btn;
}

void MainWindow::setGet_btn(QPushButton *newGet_btn)
{
    get_btn = newGet_btn;
}
</code></pre>
<p dir="auto">and the main.cpp in the <strong>appraoch 2</strong> is:</p>
<pre><code>int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    clientAPI client();
    MainWindow w();
    QObject::connect(w.getGet_btn(), &amp;QPushButton::clicked, &amp;clinet, &amp;clientAPI::get_items);
    QObject::connect(&amp;client, &amp;clientAPI::data_received, w.getTest_label(), &amp;MainWindow::update_label);
    w.show();

    return a.exec();
}
</code></pre>
<p dir="auto">Tanks a lot for your guide.<br />
both of these approaches are working as I tested them, but I want your advice for designing a software, what approach you would choose? which one is more common and the right approach?<br />
sorry of the question is long, let me know if I should make it shorter.</p>
]]></description><link>https://forum.qt.io/topic/165016/design-pattern-of-inventory-management-desktop-application</link><generator>RSS for Node</generator><lastBuildDate>Sun, 13 Sep 2026 15:21:32 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/165016.rss" rel="self" type="application/rss+xml"/><pubDate>Sun, 16 Aug 2026 16:16:56 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Design pattern of inventory management desktop application on Sun, 16 Aug 2026 18:36:30 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Approach 1 is correct.<br />
MainWindow does not need to expose its internal structure in this case. In fact, it is pretty rare that an application main window exposes its internal state like for your solution #2.<br />
One other good point is creating your API client outside of MainWindow. This allows scenarios such as passing a fake API client for testing purpose if for any reason you cannot contact/spin up your backend server. This does not seem to be the case here but still it can be useful.</p>
]]></description><link>https://forum.qt.io/post/839745</link><guid isPermaLink="true">https://forum.qt.io/post/839745</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sun, 16 Aug 2026 18:36:30 GMT</pubDate></item><item><title><![CDATA[Reply to Design pattern of inventory management desktop application on Fri, 04 Sep 2026 21:04:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sales99">@<bdi>sales99</bdi></a></p>
<p dir="auto">Beside <code>m_memberVar</code><br />
there is also</p>
<ul>
<li><code>_memberVar</code></li>
<li><code>mMemberVar</code></li>
</ul>
<p dir="auto">and more variants... which are a matter of taste.<br />
At least one of them should be picked to differ between class member and local scope variables</p>
]]></description><link>https://forum.qt.io/post/839987</link><guid isPermaLink="true">https://forum.qt.io/post/839987</guid><dc:creator><![CDATA[Pl45m4]]></dc:creator><pubDate>Fri, 04 Sep 2026 21:04:33 GMT</pubDate></item><item><title><![CDATA[Reply to Design pattern of inventory management desktop application on Fri, 04 Sep 2026 19:21:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sales99">@<bdi>sales99</bdi></a> said in <a href="/post/839973">Design pattern of inventory management desktop application</a>:</p>
<blockquote>
<p dir="auto">common practice is to designate class members with m_ otherwise you invoke easily scope crashes. otherwise both approaches are just matter of taste</p>
</blockquote>
<p dir="auto">I disagree on the "just matter of taste". Each has different practical implications which go beyond taste. On the other hand, the common practice you point is a matter of taste.</p>
]]></description><link>https://forum.qt.io/post/839986</link><guid isPermaLink="true">https://forum.qt.io/post/839986</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Fri, 04 Sep 2026 19:21:29 GMT</pubDate></item><item><title><![CDATA[Reply to Design pattern of inventory management desktop application on Fri, 04 Sep 2026 05:10:38 GMT]]></title><description><![CDATA[<p dir="auto">common practice is to designate class members with m_ otherwise you invoke easily scope crashes. otherwise both approaches are just matter of taste</p>
]]></description><link>https://forum.qt.io/post/839973</link><guid isPermaLink="true">https://forum.qt.io/post/839973</guid><dc:creator><![CDATA[sales99]]></dc:creator><pubDate>Fri, 04 Sep 2026 05:10:38 GMT</pubDate></item><item><title><![CDATA[Reply to Design pattern of inventory management desktop application on Sun, 16 Aug 2026 18:36:30 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">Approach 1 is correct.<br />
MainWindow does not need to expose its internal structure in this case. In fact, it is pretty rare that an application main window exposes its internal state like for your solution #2.<br />
One other good point is creating your API client outside of MainWindow. This allows scenarios such as passing a fake API client for testing purpose if for any reason you cannot contact/spin up your backend server. This does not seem to be the case here but still it can be useful.</p>
]]></description><link>https://forum.qt.io/post/839745</link><guid isPermaLink="true">https://forum.qt.io/post/839745</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Sun, 16 Aug 2026 18:36:30 GMT</pubDate></item></channel></rss>