<?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[Slots in the second window?]]></title><description><![CDATA[<p dir="auto">In my main window, I have</p>
<pre><code class="language-ui-&gt;setupUi(this);">    QString movie = ui-&gt;movie_name-&gt;text();
    connect(this, SIGNAL(send(QString)), List, SLOT(get_movie(QString)));
    emit send(movie);
</code></pre>
<p dir="auto">And in the List window, I need to have that slot. My lists.h is:</p>
<pre><code class="language-public">    QString getMovieName(QString movie)
    {
        return movie;
    }

</code></pre>
<p dir="auto">And in my lists.cpp, I have:</p>
<pre><code class="language-ui-&gt;setupUi(this);">    QString a;
    a = getMovieName(m);
    ui-&gt;label-&gt;setText(a);
}
</code></pre>
<p dir="auto">But, the 'm' variable cannot be used in it as it is not declared. How do I assign the movie name to the variable 'a' in lists.cpp?</p>
]]></description><link>https://forum.qt.io/topic/129424/slots-in-the-second-window</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 01:07:45 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/129424.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 16 Aug 2021 05:22:47 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Slots in the second window? on Wed, 18 Aug 2021 06:19:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rootlearner">@<bdi>RootLearner</bdi></a> said in <a href="/post/676195">Slots in the second window?</a>:</p>
<blockquote>
<p dir="auto">When receive slot is called, the ui is not updated but when I close the window, the qDebug in "opening movielist" and case 0 is run. How do I solve this?  I need it to update the ui as per the integer passed via signals.</p>
</blockquote>
<p dir="auto">For me it looks like there is a forever loop which locks the thread event loop.<br />
The emitted signals are stored in event loop, but as the thread is lock in a forever loop, the associated slots are called when forever loop ends and event loop is running.</p>
<p dir="auto">What are you doing in <code>movie</code> class?</p>
]]></description><link>https://forum.qt.io/post/676341</link><guid isPermaLink="true">https://forum.qt.io/post/676341</guid><dc:creator><![CDATA[KroMignon]]></dc:creator><pubDate>Wed, 18 Aug 2021 06:19:08 GMT</pubDate></item><item><title><![CDATA[Reply to Slots in the second window? on Tue, 17 Aug 2021 23:43:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a>  <a class="plugin-mentions-user plugin-mentions-a" href="/user/kromignon">@<bdi>KroMignon</bdi></a></p>
<pre><code>#include "movielist.h"
#include "ui_movielist.h"
#include &lt;QSqlDatabase&gt;
#include &lt;QSqlError&gt;
#include &lt;QSqlQueryModel&gt;
#include &lt;QSqlQuery&gt;
#include &lt;QDebug&gt;
#include &lt;QSqlRecord&gt;
#include &lt;QMessageBox&gt;
#include "movie.h"

Movielist::Movielist(QWidget *parent) : QDialog(parent),
                                        ui(new Ui::Movielist)
{
    ui-&gt;setupUi(this);
    QSqlDatabase myfile;
    myfile = QSqlDatabase::addDatabase("QSQLITE");
    myfile.setDatabaseName("C:/Users/user/Documents/New folder/qtcode/movie.db");
    if (!myfile.open())
    {
        qDebug() &lt;&lt; ("Failed to open the database");
    }
    else
    {
        qDebug() &lt;&lt; ("Connected");
    }
    QSqlQueryModel *model = new QSqlQueryModel();
    QSqlQuery qry;

    
}

Movielist::~Movielist()
{
    delete ui;
}

void Movielist::on_tableView_activated(const QModelIndex &amp;index)
{
    movie m;
    int c = index.column();
    QString temp = ui-&gt;tableView-&gt;model()-&gt;data(index).toString();
    qDebug() &lt;&lt; temp;
    m.setModal(true);
    hide();
    m.exec();
}

void Movielist::receive(int a)
{

    qDebug()&lt;&lt;"opening movielist";

    switch (a)
    {
    case 0:
    {
        qDebug()&lt;&lt;"case 0";
        QSqlQueryModel *model = new QSqlQueryModel();
        QSqlQuery qry;
        qry.prepare("select Name, Date, Ratings, Genre from movie order by Ratings DESC");
       qDebug()&lt;&lt;"Case 0 ko query";
        if (qry.exec())
        {
            model-&gt;setQuery(qry);
            ui-&gt;label_2-&gt;setText("Top Rated Movies");
            ui-&gt;tableView-&gt;setModel(model);
            ui-&gt;tableView-&gt;resizeColumnsToContents();
            qDebug()&lt;&lt;"case 0 query executed";
        }
        break;
    }
    case 1:
    {
        QSqlQueryModel *model1 = new QSqlQueryModel();
        QSqlQuery qry1;
        qry1.prepare("select Name, Date, Ratings, Genre from movie where Genre = 'Romantic' order by Ratings DESC ");
        if (qry1.exec())
        {
            model1-&gt;setQuery(qry1);
            ui-&gt;label_2-&gt;setText("Top Romantic Movies");
            ui-&gt;tableView-&gt;setModel(model1);
            ui-&gt;tableView-&gt;resizeColumnsToContents();
        }
        break;
    }
    }
}
</code></pre>
<p dir="auto">When receive slot is called, the ui is not updated but when I close the window, the qDebug in "opening movielist" and case 0 is run. How do I solve this?  I need it to update the ui as per the integer passed via signals.</p>
]]></description><link>https://forum.qt.io/post/676195</link><guid isPermaLink="true">https://forum.qt.io/post/676195</guid><dc:creator><![CDATA[RootLearner]]></dc:creator><pubDate>Tue, 17 Aug 2021 23:43:37 GMT</pubDate></item><item><title><![CDATA[Reply to Slots in the second window? on Mon, 16 Aug 2021 13:51:37 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> I assumed I was making it a class member by declaring it in the constructor. And I actually didn't know slots gets called automatically as soon as the signal is emitted. I only worked with 'onButtonClicked()' as a slot and it worked when I clicked the button. So, I assumed every slots will be required to be called by doing something specifically. Thank you for clearing out my misconception. I got the concept and now, I can apply it in my project!</p>
]]></description><link>https://forum.qt.io/post/676020</link><guid isPermaLink="true">https://forum.qt.io/post/676020</guid><dc:creator><![CDATA[RootLearner]]></dc:creator><pubDate>Mon, 16 Aug 2021 13:51:37 GMT</pubDate></item><item><title><![CDATA[Reply to Slots in the second window? on Mon, 16 Aug 2021 13:38:06 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/kromignon">@<bdi>KroMignon</bdi></a> It was dumb of me to not recognize it as a local variable. I didn't see I am actually declaring it in the constructor. I was thinking if the variable declared will have global scope. I messed up my concepts. Thank you for highlighting it.</p>
]]></description><link>https://forum.qt.io/post/676019</link><guid isPermaLink="true">https://forum.qt.io/post/676019</guid><dc:creator><![CDATA[RootLearner]]></dc:creator><pubDate>Mon, 16 Aug 2021 13:38:06 GMT</pubDate></item><item><title><![CDATA[Reply to Slots in the second window? on Mon, 16 Aug 2021 11:20:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rootlearner">@<bdi>RootLearner</bdi></a> As <a class="plugin-mentions-user plugin-mentions-a" href="/user/kromignon">@<bdi>KroMignon</bdi></a> suggested: learn C++ first.<br />
You declared a as local variable in lists constructor, so it only exists as long as this constructor is executed.<br />
Declare a as class member...</p>
<p dir="auto">And why do you want to call the slot? Slot is called automatically as soon as the signal is emitted.</p>
]]></description><link>https://forum.qt.io/post/675995</link><guid isPermaLink="true">https://forum.qt.io/post/675995</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Mon, 16 Aug 2021 11:20:13 GMT</pubDate></item><item><title><![CDATA[Reply to Slots in the second window? on Mon, 16 Aug 2021 11:18:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rootlearner">@<bdi>RootLearner</bdi></a> said in <a href="/post/675989">Slots in the second window?</a>:</p>
<blockquote>
<p dir="auto">Okay, I understood this. But I want to know how I am going to call this slot?</p>
</blockquote>
<p dir="auto">Please, start to learn C++ basics:</p>
<ul>
<li>what are classes</li>
<li>variable scope</li>
</ul>
<p dir="auto">If you define a local variable in a function, this variable is local to this function and can <strong>not</strong> be used in another function.</p>
]]></description><link>https://forum.qt.io/post/675992</link><guid isPermaLink="true">https://forum.qt.io/post/675992</guid><dc:creator><![CDATA[KroMignon]]></dc:creator><pubDate>Mon, 16 Aug 2021 11:18:08 GMT</pubDate></item><item><title><![CDATA[Reply to Slots in the second window? on Mon, 16 Aug 2021 10:21:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/jsulm">@<bdi>jsulm</bdi></a> Okay, I understood this. But I want to know how I am going to call this slot?<br />
My lists.cpp is:</p>
<pre><code>#include "lists.h"
#include "ui_lists.h"

lists::lists(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::lists)
{
    ui-&gt;setupUi(this);
    QString a;
//I should be calling the slot here??? If yes, how?
    qDebug()&lt;&lt;a;//just an example
}

lists::~lists()
{
    delete ui;
}

void lists::get_movie(QString m)
{
    a = m; // I
    ui-&gt;label-&gt;setText(m);
}
</code></pre>
<p dir="auto">This says a is an undeclared identifier. How do I call this slot and where?<br />
While calling, will it not ask for variable 'm'?</p>
]]></description><link>https://forum.qt.io/post/675989</link><guid isPermaLink="true">https://forum.qt.io/post/675989</guid><dc:creator><![CDATA[RootLearner]]></dc:creator><pubDate>Mon, 16 Aug 2021 10:21:59 GMT</pubDate></item><item><title><![CDATA[Reply to Slots in the second window? on Mon, 16 Aug 2021 09:17:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rootlearner">@<bdi>RootLearner</bdi></a> Can you please explain what variable in what second window?<br />
Is this second window the List class?<br />
If so then its dead easy:</p>
<pre><code>// In List class
void List::get_movie(QString m)
{
    a = m; // I assume a was defined as class member, but could also be a local variable
    ui-&gt;label-&gt;setText(m);
}
</code></pre>
]]></description><link>https://forum.qt.io/post/675973</link><guid isPermaLink="true">https://forum.qt.io/post/675973</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Mon, 16 Aug 2021 09:17:48 GMT</pubDate></item><item><title><![CDATA[Reply to Slots in the second window? on Mon, 16 Aug 2021 09:14:27 GMT]]></title><description><![CDATA[<p dir="auto">I understand how we update the value in the ui. But I want to assign that value to a new variable in my second window. As in, I want to pass that username in a database and run a query. I cannot get that movie name under a variable. That is my main problem. I read documentations and also searched other projects. I just do not tend to get the idea of how I can assign the value into a new variable.</p>
]]></description><link>https://forum.qt.io/post/675971</link><guid isPermaLink="true">https://forum.qt.io/post/675971</guid><dc:creator><![CDATA[RootLearner]]></dc:creator><pubDate>Mon, 16 Aug 2021 09:14:27 GMT</pubDate></item><item><title><![CDATA[Reply to Slots in the second window? on Mon, 16 Aug 2021 06:19:17 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rootlearner">@<bdi>RootLearner</bdi></a> Please read <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><br />
I don't understand what you are doing? Where is your slot get_movie(QString) definition and what is it doing?<br />
All you have to do is:</p>
<pre><code>// In List class
void List::get_movie(QString m)
{
    ui-&gt;label-&gt;setText(m);
}
</code></pre>
]]></description><link>https://forum.qt.io/post/675939</link><guid isPermaLink="true">https://forum.qt.io/post/675939</guid><dc:creator><![CDATA[jsulm]]></dc:creator><pubDate>Mon, 16 Aug 2021 06:19:17 GMT</pubDate></item></channel></rss>