<?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[Introduction to GUI Qt Test???]]></title><description><![CDATA[<p dir="auto">Good day,<br />
I have created a subdir project that contains first a Qt GUI project of a currency converter (see picture below) and a second project, a QtTest to test the converter.<br />
<img src="https://ddgobkiprc33d.cloudfront.net/37322829-dff6-4237-ac86-13079d0444c2.png" alt="72c0544a-9b48-493c-b3e9-2763e015af68-image.png" class=" img-fluid img-markdown" /><br />
Here is the .pro file of the subdir project:</p>
<pre><code>TEMPLATE = subdirs

SUBDIRS += \
    CurrencyConverter \
    QtTest

tests.subdirs = QtTest
app.subdirs = CurrencyConverter

QtTest.depends = CurrencyConverter

</code></pre>
<p dir="auto">and here is the .pro file of the Qt Test project</p>
<pre><code>QT += testlib gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

DEFINES += QT_DEPRECATED_WARNINGS

CONFIG += qt warn_on depend_includepath testcase

TEMPLATE = app
INCLUDEPATH += ../CurrencyConverter

SOURCES +=  tst_testconverter.cpp
</code></pre>
<p dir="auto">When I add the view of the currency project in my test case, I got an undefined reference of the constructor of the View. What am doing wrong?</p>
<pre><code>#include &lt;QtTest&gt;
#include &lt;QCoreApplication&gt;
#include "view.h"

// add necessary includes here

class testConverter : public QObject
{
    Q_OBJECT

public:
    testConverter();
    ~testConverter();

private slots:
    void initTestCase();
    void cleanupTestCase();
    void test_case1();

};

testConverter::testConverter()
{

}

testConverter::~testConverter()
{

}

void testConverter::initTestCase()
{

}

void testConverter::cleanupTestCase()
{

}

void testConverter::test_case1()
{
    View view; // the problem occurs here

}

QTEST_MAIN(testConverter)

#include "tst_testconverter.moc"
</code></pre>
]]></description><link>https://forum.qt.io/topic/115410/introduction-to-gui-qt-test</link><generator>RSS for Node</generator><lastBuildDate>Mon, 15 Jun 2026 07:05:12 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/115410.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 01 Jun 2020 08:04:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Introduction to GUI Qt Test??? on Mon, 01 Jun 2020 21:46:54 GMT]]></title><description><![CDATA[<p dir="auto">What OS are you on ?</p>
]]></description><link>https://forum.qt.io/post/598395</link><guid isPermaLink="true">https://forum.qt.io/post/598395</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 01 Jun 2020 21:46:54 GMT</pubDate></item><item><title><![CDATA[Reply to Introduction to GUI Qt Test??? on Mon, 01 Jun 2020 20:12:45 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/user/sgaist">@<bdi>SGaist</bdi></a><br />
I have tried the first bullet by refactoring the code having an app as main project that just call my lib:</p>
<pre><code>#include "mainwindow.h"
#include "currencyconverter.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    CurrencyConverter *currency = new CurrencyConverter(parent);

    setCentralWidget(currency);
}
</code></pre>
<p dir="auto">and my main .pro file looks like this:</p>
<pre><code>QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

CONFIG += c++11

# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS

# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
INCLUDEPATH += \
              ../CurrencyConverter

LIBS += \
            -L../CurrencyConverter

SOURCES += \
    main.cpp \
    mainwindow.cpp

HEADERS += \
    mainwindow.h

# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
</code></pre>
<p dir="auto">When compiling, I'm still getting undefined reference to CurrencyConverter at line where currency pointer is initiaze. the first bullet seems not working for me.<br />
for the second bullet, what you do you mean by  "build the files needed within the test sub project." ho do you do that in .pro file?</p>
]]></description><link>https://forum.qt.io/post/598387</link><guid isPermaLink="true">https://forum.qt.io/post/598387</guid><dc:creator><![CDATA[Massi]]></dc:creator><pubDate>Mon, 01 Jun 2020 20:12:45 GMT</pubDate></item><item><title><![CDATA[Reply to Introduction to GUI Qt Test??? on Mon, 01 Jun 2020 10:45:07 GMT]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bonnie">@<bdi>Bonnie</bdi></a> is right. Your current issue is that you don't build the class along your test hence your error.</p>
<p dir="auto">You have several way of solving this:</p>
<ul>
<li>make a library out of the components of your application and link against it. You app project will mainly be a main.cpp file creating the needed objects using that library as well.</li>
<li>stay as you are currently and build the files needed within the test sub project.</li>
</ul>
]]></description><link>https://forum.qt.io/post/598283</link><guid isPermaLink="true">https://forum.qt.io/post/598283</guid><dc:creator><![CDATA[SGaist]]></dc:creator><pubDate>Mon, 01 Jun 2020 10:45:07 GMT</pubDate></item><item><title><![CDATA[Reply to Introduction to GUI Qt Test??? on Mon, 01 Jun 2020 09:34:48 GMT]]></title><description><![CDATA[<p dir="auto">I'm not familiar with Qt Test, I'm just trying if I can simulate mouse click event I could probably test the GUI with but I'm not sure if I'm in the right path</p>
]]></description><link>https://forum.qt.io/post/598267</link><guid isPermaLink="true">https://forum.qt.io/post/598267</guid><dc:creator><![CDATA[Massi]]></dc:creator><pubDate>Mon, 01 Jun 2020 09:34:48 GMT</pubDate></item><item><title><![CDATA[Reply to Introduction to GUI Qt Test??? on Mon, 01 Jun 2020 09:15:49 GMT]]></title><description><![CDATA[<p dir="auto">The sub-project is not linked to <code>View</code>, so it does not know how to create a <code>View</code>, that's "undefined reference of the constructor" means.<br />
But I don't know what's the usual way to test an app's internal class...</p>
]]></description><link>https://forum.qt.io/post/598262</link><guid isPermaLink="true">https://forum.qt.io/post/598262</guid><dc:creator><![CDATA[Bonnie]]></dc:creator><pubDate>Mon, 01 Jun 2020 09:15:49 GMT</pubDate></item><item><title><![CDATA[Reply to Introduction to GUI Qt Test??? on Mon, 01 Jun 2020 09:12:33 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mrjj">@<bdi>mrjj</bdi></a><br />
thanks for your reply, Here is the view:</p>
<pre><code>#include &lt;QMainWindow&gt;

QT_BEGIN_NAMESPACE
namespace Ui { class View; }
QT_END_NAMESPACE

class Controller;

class View : public QMainWindow
{
    Q_OBJECT

public:
    View(QWidget *parent = nullptr);
    ~View();
    void setController(Controller *controller);

public slots:
    void set_amount(const QString&amp; val);
    void get_recieve();

private:
    Ui::View *ui;
    Controller *m_controller;
    friend class testConverter;
};
</code></pre>
<p dir="auto">and its cpp</p>
<pre><code>View::View(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::View)
    , m_controller(nullptr)
{
    ui-&gt;setupUi(this);
    ui-&gt;amount_el-&gt;setText(QString::number(0.00));

    connect(ui-&gt;amount_el, SIGNAL(textChanged(const QString &amp;)),
            this, SLOT(set_amount(const QString &amp;)));

    connect(ui-&gt;convert_btn, SIGNAL(clicked()),
            this, SLOT(get_recieve()));
}
</code></pre>
<p dir="auto">The parent by default is nullptr</p>
]]></description><link>https://forum.qt.io/post/598259</link><guid isPermaLink="true">https://forum.qt.io/post/598259</guid><dc:creator><![CDATA[Massi]]></dc:creator><pubDate>Mon, 01 Jun 2020 09:12:33 GMT</pubDate></item><item><title><![CDATA[Reply to Introduction to GUI Qt Test??? on Mon, 01 Jun 2020 08:52:00 GMT]]></title><description><![CDATA[<p dir="auto">Hi<br />
But does the view constructor takes no arguments ?<br />
Normally it takes a parent.</p>
]]></description><link>https://forum.qt.io/post/598254</link><guid isPermaLink="true">https://forum.qt.io/post/598254</guid><dc:creator><![CDATA[mrjj]]></dc:creator><pubDate>Mon, 01 Jun 2020 08:52:00 GMT</pubDate></item></channel></rss>