<?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[Simple qt help with data between forms]]></title><description><![CDATA[<p dir="auto">Hello,</p>
<p dir="auto">I am new to QT but not C++, I am trying to learn about slots and signals but am stuck on sending data between forms.  I have done a lot of looking on the Internet but can't seem to make a connection (no pun intended) in my mind.   Because its easier for me to learn this way, it would be helpful for me to get my code working and study and play with that.</p>
<p dir="auto">So I have two forms mainwindow.cpp and secdialog.cpp.  On the main window a button (pushbutton) is clicked which opens the form created by secdialog.cpp.  In secdialog, I have a lineEdit box and a pushbutton.  In a nut shell I want to be able to have the data thats entered in to the lineEdit box transferred over to a string value in mainwindow.cpp class.</p>
<p dir="auto">I have seen some example on the Internet but none dealing with just storing the data in to a data type.</p>
<p dir="auto">Maybe someone could please help me?</p>
<p dir="auto">Thanks</p>
<p dir="auto">main.cpp<br />
[code]<br />
#include "mainwindow.h"<br />
#include &lt;QApplication&gt;<br />
#include &lt;unistd.h&gt;</p>
<p dir="auto">int main(int argc, char *argv[])<br />
{<br />
QApplication a(argc, argv);<br />
MainWindow w;<br />
w.show();</p>
<pre><code>return a.exec&amp;#40;&amp;#41;;
</code></pre>
<p dir="auto">}<br />
[/code]</p>
<p dir="auto">mainwindow.cpp</p>
<p dir="auto">[code]<br />
#include "mainwindow.h"<br />
#include "ui_mainwindow.h"<br />
#include "secdialog.h"</p>
<p dir="auto">MainWindow::MainWindow(QWidget *parent) :<br />
QMainWindow(parent),<br />
ui(new Ui::MainWindow)<br />
{<br />
ui-&gt;setupUi(this);<br />
}</p>
<p dir="auto">MainWindow::~MainWindow()<br />
{<br />
delete ui;<br />
}</p>
<p dir="auto">void MainWindow::on_pushButton_clicked()<br />
{<br />
SecDialog blah;<br />
blah.setModal(true);<br />
blah.exec();</p>
<p dir="auto">}<br />
[/code]</p>
<p dir="auto">secdialog.cpp</p>
<p dir="auto">[code]<br />
#include "secdialog.h"<br />
#include "ui_secdialog.h"<br />
#include &lt;QString&gt;<br />
using namespace std;</p>
<p dir="auto">SecDialog::SecDialog(QWidget *parent) :<br />
QDialog(parent),<br />
ui(new Ui::SecDialog)<br />
{<br />
ui-&gt;setupUi(this);</p>
<p dir="auto">}</p>
<p dir="auto">SecDialog::~SecDialog()<br />
{<br />
delete ui;</p>
<p dir="auto">}</p>
<p dir="auto">void SecDialog::on_pushButton_clicked()<br />
{<br />
// data = ui-&gt;lineEdit-&gt;text();   i want to do something like this! but i know i can't</p>
<p dir="auto">}<br />
[/code]</p>
<p dir="auto">mainwindow.h</p>
<p dir="auto">[code]<br />
#ifndef MAINWINDOW_H<br />
#define MAINWINDOW_H</p>
<p dir="auto">#include &lt;QMainWindow&gt;<br />
#include"secdialog.h"<br />
namespace Ui {<br />
class MainWindow;<br />
}</p>
<p dir="auto">class MainWindow : public QMainWindow<br />
{<br />
Q_OBJECT</p>
<p dir="auto">public:<br />
explicit MainWindow(QWidget *parent = 0);<br />
~MainWindow();</p>
<p dir="auto">private slots:</p>
<pre><code>void on_pushButton_clicked();
</code></pre>
<p dir="auto">private:<br />
Ui::MainWindow *ui;<br />
SecDialog *blah;<br />
QString data;</p>
<p dir="auto">};</p>
<p dir="auto">#endif // MAINWINDOW_H</p>
<p dir="auto">[/code]</p>
<p dir="auto">secdialog.h<br />
[code]<br />
#ifndef SECDIALOG_H<br />
#define SECDIALOG_H</p>
<p dir="auto">#include &lt;QDialog&gt;</p>
<p dir="auto">namespace Ui {<br />
class SecDialog;<br />
}</p>
<p dir="auto">class SecDialog : public QDialog<br />
{<br />
Q_OBJECT</p>
<p dir="auto">public:<br />
explicit SecDialog(QWidget *parent = 0);<br />
~SecDialog();</p>
<p dir="auto">private slots:<br />
void on_pushButton_clicked();</p>
<p dir="auto">private:<br />
Ui::SecDialog *ui;<br />
QString i;<br />
};</p>
<p dir="auto">#endif // SECDIALOG_H</p>
<p dir="auto">[/code]</p>
]]></description><link>https://forum.qt.io/topic/48254/simple-qt-help-with-data-between-forms</link><generator>RSS for Node</generator><lastBuildDate>Sun, 19 Apr 2026 20:20:58 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/48254.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 17 Nov 2014 20:53:27 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Simple qt help with data between forms on Thu, 04 Dec 2014 20:28:01 GMT]]></title><description><![CDATA[<p dir="auto">That would be a great help if you could!  thanks</p>
]]></description><link>https://forum.qt.io/post/253204</link><guid isPermaLink="true">https://forum.qt.io/post/253204</guid><dc:creator><![CDATA[bwcal1999]]></dc:creator><pubDate>Thu, 04 Dec 2014 20:28:01 GMT</pubDate></item><item><title><![CDATA[Reply to Simple qt help with data between forms on Thu, 04 Dec 2014 20:12:47 GMT]]></title><description><![CDATA[<p dir="auto">You are right. I did not realize that you need the data while the dialog is open.<br />
In this case you need to use signal/slot mechanism to send data to mainwindow.<br />
I don't have an example right now. Will update post later.</p>
]]></description><link>https://forum.qt.io/post/253201</link><guid isPermaLink="true">https://forum.qt.io/post/253201</guid><dc:creator><![CDATA[andreyc]]></dc:creator><pubDate>Thu, 04 Dec 2014 20:12:47 GMT</pubDate></item><item><title><![CDATA[Reply to Simple qt help with data between forms on Thu, 04 Dec 2014 19:32:49 GMT]]></title><description><![CDATA[<p dir="auto">thank you,<br />
for some reason i was under the impression calling the new form was blocking and nothing could be ran after that until execution was completed.</p>
]]></description><link>https://forum.qt.io/post/253196</link><guid isPermaLink="true">https://forum.qt.io/post/253196</guid><dc:creator><![CDATA[bwcal1999]]></dc:creator><pubDate>Thu, 04 Dec 2014 19:32:49 GMT</pubDate></item><item><title><![CDATA[Reply to Simple qt help with data between forms on Thu, 04 Dec 2014 18:30:51 GMT]]></title><description><![CDATA[<p dir="auto">secdialog.h<br />
@<br />
class SecDialog : public QDialog<br />
{<br />
public:<br />
...<br />
QString data() const;<br />
...<br />
}<br />
@<br />
secdialog.cpp<br />
@<br />
...<br />
QString SecDialog::data() const<br />
{<br />
return ui-&gt;lineEdit-&gt;text();<br />
}<br />
...<br />
@<br />
mainwindow.cpp<br />
@<br />
...<br />
void MainWindow::on_pushButton_clicked()<br />
{<br />
SecDialog blah;<br />
blah.setModal(true);<br />
blah.exec();<br />
qDebug() &lt;&lt; blah.data();<br />
}<br />
...<br />
@</p>
]]></description><link>https://forum.qt.io/post/253194</link><guid isPermaLink="true">https://forum.qt.io/post/253194</guid><dc:creator><![CDATA[andreyc]]></dc:creator><pubDate>Thu, 04 Dec 2014 18:30:51 GMT</pubDate></item><item><title><![CDATA[Reply to Simple qt help with data between forms on Thu, 04 Dec 2014 18:15:36 GMT]]></title><description><![CDATA[<p dir="auto">hi, is there a way you could be a little more specific like using my situation specific.</p>
<p dir="auto">Thanks!</p>
]]></description><link>https://forum.qt.io/post/253191</link><guid isPermaLink="true">https://forum.qt.io/post/253191</guid><dc:creator><![CDATA[bwcal1999]]></dc:creator><pubDate>Thu, 04 Dec 2014 18:15:36 GMT</pubDate></item></channel></rss>