qt 将登陆界面的内容传到主界面
2015-06-01 09:21
561 查看
还是之前那个项目,
在dialog.h里 的public里声明一个变量str1,
public:
当然这个变量是获取编辑框内容的,上一篇有具体代码。
在mainwindow.h里,在private声明一个变量str1,这个str1 非之前那个str1,当让声明成其他也可以,这时explicit Mainwindow,里添加QString n.
class MainWindow
: public
QMainWindow
int main(int argc, char *argv[])
在dialog.h里 的public里声明一个变量str1,
public:
explicit Dialog(QWidget *parent = 0);
~Dialog();
QString str1;
当然这个变量是获取编辑框内容的,上一篇有具体代码。
在mainwindow.h里,在private声明一个变量str1,这个str1 非之前那个str1,当让声明成其他也可以,这时explicit Mainwindow,里添加QString n.
class MainWindow
: public
QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QString n,QWidget *parent = 0);
~MainWindow();
Dialog m1;
protected:
private slots:
void on_pushButton_clicked();
void on_sendButton_clicked();
void on_pushButton_3_clicked();
private:
Ui::MainWindow *ui;
QString str1;
}; 下面转到mainwindow.cpp,QString n 和str1=n; MainWindow::MainWindow(QString n,QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
str1=n;
ui->dateTimeEdit->setDateTime(QDateTime::currentDateTime());
ui->dateTimeEdit->setDisplayFormat(tr("yyyy-MM-dd hh:mm:ss"));
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(OnButtonClicked()));
ui->textBrowser->append(str1);
ui->textBrowser->append("You have loged in,welcome!");
}最后转到main.cpp
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString str1;
Dialog m;
if(m.exec()==QDialog::Accepted)
{
str1=m.str1;
MainWindow w(str1);
w.show();
return a.exec();
}
else return 0;
}这里又声明了一个str1,此str1又非之前的两个str1。这样登陆界面的值就传到主界面了。
相关文章推荐
- QT学习 第一章:基本对话框
- 使用Shiboken为C++和Qt库创建Python绑定
- Qt实现图片移动实例(图文教程)
- Qt for Android开发实例教程
- QModelIndex/Role/Model介紹<二>
- 基于PyQt5的快速开发框架QFramer
- ok6410开发板移植DirectFB手记
- 【笔记】给Qt内嵌一个Chrome吧
- 【算法】最短路径之A*搜索
- qt入门必备
- 在 Qt4 中使用 C++11
- Hello Word ~ v0.2.2 背单词软件发布 -- By WHYPRO
- ubuntu下opencv和qt的安装配置
- linux下opengl的安装(with qt)
- qt 学习小节
- QT的命名风格
- QT 中的sleep
- QT 串口的监控
- 在VS2010下配置QT和ITK+VTK
- QLibrary&QPluginLoader 和plugin(转)