QT菜鸟求助,现有两个Dialog对话框,Dialog1里有一个lineedit1和一些数字按钮(点击按钮能实现将数字显示到lineedit1中),还有一个OK按钮,Dialog2里只有一个lineedit2,怎么将Dialog1里lineedit1的内容在按下OK按钮后显示到Dialog2中的lineedit2中???求大神帮忙,理论的东西不好理解,最好有个小例子的代码,小弟刚学QT一星期,万分感谢!!!
------解决方案--------------------
体力活阿。。。刚才无聊,按你的要求做了个小的project,代码如下:
dialog1.h:
#ifndef DIALOG1_H
#define DIALOG1_H
#include <QDialog>
namespace Ui {
class Dialog1;
}
class Dialog1 : public QDialog
{
Q_OBJECT
public:
explicit Dialog1(QWidget *parent = 0);
~Dialog1();
signals:
void selectedButton(QString text);
private slots:
void button1();
void button2();
void ok();
private:
Ui::Dialog1 *ui;
};
#endif // DIALOG1_H
dialog1.cpp
#include "dialog1.h"
#include "ui_dialog1.h"
Dialog1::Dialog1(QWidget *parent) :
QDialog(parent),
ui(new Ui::Dialog1)
{
ui->setupUi(this);
connect(ui->pButton_1,SIGNAL(clicked()),this,SLOT(button1()));
connect(ui->pButton_2,SIGNAL(clicked()),this,SLOT(button2()));
connect(ui->pButton_3,SIGNAL(clicked()),this,SLOT(ok()));
}
Dialog1::~Dialog1()
{
delete ui;
}
void Dialog1::button1()
{
ui->lineEdit1->setText(tr("1"));
}
void Dialog1::button2()
{
ui->lineEdit1->setText(tr("2"));
}
void Dialog1::ok()
{
emit selectedButton(ui->lineEdit1->text());
}
dialog1.ui:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog1</class>
<widget class="QDialog" name="Dialog1">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>224</width>
<height>104</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog1</string>
</property>
<widget class="QLineEdit" name="lineEdit1">
<property name="geometry">
<rect>
<x>90</x>
<y>20</y>
<width>113</width>
<height>27</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>30</x>
<y>20</y>
<width>61</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>number</string>
</property>
</widget>
<widget class="QPushButton" name="pButton_1">
<property name="geometry">
<rect>
<x>10</x>
<y>60</y>
<width>61</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>1</string>
</property>
</widget>
<widget class="QPushButton" name="pButton_2">
<property name="geometry">
<rect>
<x>80</x>
<y>60</y>
<width>61</width>
<height>27</height>
</rect>
</property>
<property name="text">
<string>2</string>